Skip to content

Commit

Permalink
Merge pull request #1380 from kiwix/feature/macgills/#1165-remove-cus…
Browse files Browse the repository at this point in the history
…tom-external

#1165 New external storage disappears on screen rotation
  • Loading branch information
macgills authored Aug 16, 2019
2 parents 189e1b4 + 0785df2 commit 786d168
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 275 deletions.

This file was deleted.

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 app/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.java

This file was deleted.

74 changes: 74 additions & 0 deletions app/src/main/java/eu/mhutti1/utils/storage/StorageSelectDialog.kt
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
}
}
Loading

0 comments on commit 786d168

Please sign in to comment.