-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cca801
commit bfd0449
Showing
10 changed files
with
327 additions
and
10 deletions.
There are no files selected for viewing
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
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
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
86 changes: 86 additions & 0 deletions
86
app/src/main/java/space/celestia/mobilecelestia/settings/SettingsDataLocationFragment.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,86 @@ | ||
/* | ||
* SettingsDataLocationFragment.kt | ||
* | ||
* Copyright (C) 2001-2020, the Celestia Development Team | ||
* | ||
* 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 2 | ||
* of the License, or (at your option) any later version. | ||
*/ | ||
|
||
package space.celestia.mobilecelestia.settings | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import space.celestia.mobilecelestia.MainActivity | ||
import space.celestia.mobilecelestia.R | ||
import space.celestia.mobilecelestia.utils.CelestiaString | ||
|
||
class SettingsDataLocationFragment : SettingsBaseFragment() { | ||
|
||
private var listener: Listener? = null | ||
|
||
private val listAdapter by lazy { SettingsDataLocationRecyclerViewAdapter(listener) } | ||
|
||
override val title: String | ||
get() = CelestiaString("Data Location", "") | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
val view = | ||
inflater.inflate(R.layout.fragment_settings_current_time_list, container, false) | ||
|
||
// Set the adapter | ||
if (view is RecyclerView) { | ||
with(view) { | ||
layoutManager = LinearLayoutManager(context) | ||
listAdapter.update(customConfig, customDataDir) | ||
adapter = listAdapter | ||
} | ||
} | ||
return view | ||
} | ||
|
||
override fun onAttach(context: Context) { | ||
super.onAttach(context) | ||
if (context is Listener) { | ||
listener = context | ||
} else { | ||
throw RuntimeException("$context must implement SettingsDataLocationFragment.Listener") | ||
} | ||
} | ||
|
||
override fun onDetach() { | ||
super.onDetach() | ||
listener = null | ||
} | ||
|
||
override fun reload() { | ||
listAdapter.update(customConfig, customDataDir) | ||
listAdapter.notifyDataSetChanged() | ||
} | ||
|
||
interface Listener { | ||
fun onDataLocationNeedReset() | ||
fun onDataLocationRequested(dataType: DataType) | ||
} | ||
|
||
companion object { | ||
val customConfig: Boolean | ||
get() = MainActivity.customConfigFilePath != null | ||
val customDataDir: Boolean | ||
get() = MainActivity.customDataDirPath != null | ||
|
||
@JvmStatic | ||
fun newInstance() = | ||
SettingsDataLocationFragment() | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...in/java/space/celestia/mobilecelestia/settings/SettingsDataLocationRecyclerViewAdapter.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,101 @@ | ||
/* | ||
* SettingsDataLocationRecyclerViewAdapter.kt | ||
* | ||
* Copyright (C) 2001-2020, the Celestia Development Team | ||
* | ||
* 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 2 | ||
* of the License, or (at your option) any later version. | ||
*/ | ||
|
||
package space.celestia.mobilecelestia.settings | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import space.celestia.mobilecelestia.common.CommonSectionV2 | ||
import space.celestia.mobilecelestia.common.CommonTextViewHolder | ||
import space.celestia.mobilecelestia.common.RecyclerViewItem | ||
import space.celestia.mobilecelestia.common.SeparatorHeaderRecyclerViewAdapter | ||
import space.celestia.mobilecelestia.core.CelestiaAppCore | ||
import space.celestia.mobilecelestia.utils.CelestiaString | ||
|
||
enum class DataType { | ||
Config, DataDirectory; | ||
} | ||
|
||
interface DataLocationItem : RecyclerViewItem { | ||
val title: String | ||
val subtitle: String? | ||
} | ||
|
||
interface DataLocationDisplayItem : DataLocationItem { | ||
val custom: Boolean | ||
val type: DataType | ||
|
||
override val title: String | ||
get() = if (type == DataType.Config) CelestiaString("Config File", "") else CelestiaString("Data Directory", "") | ||
|
||
override val subtitle: String? | ||
get() = if (custom) CelestiaString("Custom", "") else CelestiaString("Default", "") | ||
} | ||
|
||
class SpecificDataLocationItem(override val custom: Boolean, override val type: DataType) : DataLocationDisplayItem | ||
|
||
class ResetDataLocationItem : DataLocationItem { | ||
override val title: String | ||
get() = CelestiaString("Reset to Default", "") | ||
override val subtitle: String? | ||
get() = null | ||
} | ||
|
||
class SettingsDataLocationRecyclerViewAdapter( | ||
private val listener: SettingsDataLocationFragment.Listener? | ||
) : SeparatorHeaderRecyclerViewAdapter(listOf()) { | ||
|
||
override fun onItemSelected(item: RecyclerViewItem) { | ||
if (item is ResetDataLocationItem) { | ||
listener?.onDataLocationNeedReset() | ||
} else if (item is DataLocationDisplayItem) { | ||
listener?.onDataLocationRequested(item.type) | ||
} | ||
} | ||
|
||
override fun itemViewType(item: RecyclerViewItem): Int { | ||
if (item is DataLocationItem) | ||
return SETTING_ITEM | ||
return super.itemViewType(item) | ||
} | ||
|
||
override fun createVH(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
if (viewType == SETTING_ITEM) { | ||
return CommonTextViewHolder(parent) | ||
} | ||
return super.createVH(parent, viewType) | ||
} | ||
|
||
override fun bindVH(holder: RecyclerView.ViewHolder, item: RecyclerViewItem) { | ||
if (item is DataLocationItem && holder is CommonTextViewHolder) { | ||
val core = CelestiaAppCore.shared() | ||
holder.title.text = item.title | ||
holder.detail.visibility = View.VISIBLE | ||
holder.detail.text = item.subtitle | ||
return | ||
} | ||
super.bindVH(holder, item) | ||
} | ||
|
||
fun update(customConfig: Boolean, customDataDir: Boolean) { | ||
val sections = ArrayList<CommonSectionV2>() | ||
sections.add(CommonSectionV2(listOf(SpecificDataLocationItem(customConfig, DataType.Config), | ||
SpecificDataLocationItem(customDataDir, DataType.DataDirectory) | ||
), "", CelestiaString("Configuration will take effect after a restart.", ""))) | ||
sections.add(CommonSectionV2(listOf(ResetDataLocationItem()), null)) | ||
updateSectionsWithHeader(sections) | ||
} | ||
|
||
private companion object { | ||
const val SETTING_ITEM = 0 | ||
} | ||
} |
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
Oops, something went wrong.