-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…tom-external #1165 New external storage disappears on screen rotation
- Loading branch information
Showing
9 changed files
with
173 additions
and
275 deletions.
There are no files selected for viewing
72 changes: 0 additions & 72 deletions
72
app/src/main/java/eu/mhutti1/utils/storage/StorageSelectArrayAdapter.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
app/src/main/java/eu/mhutti1/utils/storage/StorageSelectArrayAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2016 Isaac Hutt <mhutti1@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
package eu.mhutti1.utils.storage | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import kotlinx.android.extensions.LayoutContainer | ||
import kotlinx.android.synthetic.main.device_item.file_name | ||
import kotlinx.android.synthetic.main.device_item.file_size | ||
import org.kiwix.kiwixmobile.R | ||
import org.kiwix.kiwixmobile.R.string | ||
import org.kiwix.kiwixmobile.extensions.inflate | ||
|
||
internal class StorageSelectArrayAdapter( | ||
context: Context, | ||
devices: List<StorageDevice> | ||
) : ArrayAdapter<StorageDevice>(context, 0, devices) { | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||
var convertView = convertView | ||
|
||
val holder: ViewHolder | ||
if (convertView == null) { | ||
convertView = parent.inflate(R.layout.device_item, false) | ||
holder = ViewHolder(convertView) | ||
convertView.tag = holder | ||
} else { | ||
holder = convertView.tag as ViewHolder | ||
} | ||
holder.bind(getItem(position)!!) | ||
|
||
return convertView | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
internal inner class ViewHolder(override val containerView: View) : LayoutContainer { | ||
fun bind(device: StorageDevice) { | ||
file_name.setText(if (device.isInternal) string.internal_storage else string.external_storage) | ||
file_size.text = device.availableSpace + " / " + device.totalSize | ||
} | ||
} | ||
} |
114 changes: 0 additions & 114 deletions
114
app/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
app/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2016 Isaac Hutt <mhutti1@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
package eu.mhutti1.utils.storage | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.AdapterView.OnItemClickListener | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.FragmentManager | ||
import kotlinx.android.synthetic.main.storage_select_dialog.device_list | ||
import kotlinx.android.synthetic.main.storage_select_dialog.title | ||
import org.kiwix.kiwixmobile.R | ||
import org.kiwix.kiwixmobile.utils.StyleUtils | ||
|
||
class StorageSelectDialog : DialogFragment() { | ||
|
||
private var onSelectAction: ((StorageDevice) -> Unit)? = null | ||
private var mAdapter: StorageSelectArrayAdapter? = null | ||
|
||
private var mTitle: String? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
setStyle(STYLE_NORMAL, StyleUtils.dialogStyle()) | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View = inflater.inflate(R.layout.storage_select_dialog, container, false) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
title.text = mTitle | ||
mAdapter = StorageSelectArrayAdapter( | ||
activity!!, | ||
StorageDeviceUtils.getStorageDevices(activity!!, true) | ||
) | ||
device_list.adapter = mAdapter | ||
device_list.onItemClickListener = OnItemClickListener { _, _, position, _ -> | ||
onSelectAction?.invoke(mAdapter!!.getItem(position)!!) | ||
dismiss() | ||
} | ||
} | ||
|
||
override fun show(fm: FragmentManager, text: String) { | ||
mTitle = text | ||
super.show(fm, text) | ||
} | ||
|
||
fun setOnSelectListener(onSelectAction: (StorageDevice) -> Unit) { | ||
this.onSelectAction = onSelectAction | ||
} | ||
} |
Oops, something went wrong.