mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated nearby/fragments/NearbyParentFragment.java to nearby/fragments/NearbyParentFragment.kt
This commit is contained in:
parent
697fa4c8c4
commit
2178c4246d
3 changed files with 23 additions and 26 deletions
|
|
@ -138,6 +138,7 @@ open class CommonsApplicationModule(private val applicationContext: Context) {
|
|||
*/
|
||||
@Provides
|
||||
@Named("default_preferences")
|
||||
@Singleton
|
||||
open fun providesDefaultKvStore(context: Context, gson: Gson): JsonKvStore =
|
||||
JsonKvStore(context, "${context.packageName}_preferences", gson)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,18 @@ package fr.free.nrw.commons.di
|
|||
import android.app.Activity
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
class NearbyParentFragmentModule {
|
||||
@Provides
|
||||
fun NearbyParentFragment.providesActivity(): Activity = activity!!
|
||||
@Provides
|
||||
fun providesApplicationKvStore(
|
||||
@Named("default_preferences") kvStore: JsonKvStore
|
||||
): JsonKvStore {
|
||||
return kvStore
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -306,11 +306,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
*/
|
||||
val WLM_URL = "https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"
|
||||
|
||||
fun newInstance(): NearbyParentFragment {
|
||||
val fragment = NearbyParentFragment()
|
||||
fragment.retainInstance = true
|
||||
return fragment
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
|
@ -701,10 +697,19 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
searchHandler.removeCallbacks(searchRunnable!!)
|
||||
presenter!!.removeNearbyPreferences(applicationKvStore!!)
|
||||
searchRunnable?.let {
|
||||
searchHandler.removeCallbacks(it)
|
||||
} ?: run {
|
||||
Timber.w("NearbyParentFragment: searchRunnable is null")
|
||||
}
|
||||
|
||||
if (presenter == null) Timber.w("NearbyParentFragment: presenter is null")
|
||||
if (applicationKvStore == null) Timber.w("NearbyParentFragment: applicationKvStore is null")
|
||||
|
||||
presenter?.removeNearbyPreferences(applicationKvStore ?: return)
|
||||
}
|
||||
|
||||
|
||||
private fun initViews() {
|
||||
Timber.d("init views called")
|
||||
initBottomSheets()
|
||||
|
|
@ -1341,6 +1346,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private fun showOpenFileDialog(context: Context, fileName: String, isGPX: Boolean) {
|
||||
val title = getString(R.string.file_saved_successfully)
|
||||
val message =
|
||||
|
|
@ -2486,32 +2492,14 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
|||
const val WLM_URL: String =
|
||||
"https://commons.wikimedia.org/wiki/Commons:Mobile_app/Contributing_to_WLM_using_the_app"
|
||||
|
||||
@JvmStatic // This makes it callable as a static method from Java
|
||||
fun newInstance(): NearbyParentFragment {
|
||||
val fragment = NearbyParentFragment()
|
||||
fragment.retainInstance = true
|
||||
return fragment
|
||||
}
|
||||
|
||||
fun saveFile(string: String, fileName: String): Boolean {
|
||||
if (!isExternalStorageWritable) {
|
||||
return false
|
||||
}
|
||||
|
||||
val downloadsDir = Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS
|
||||
)
|
||||
val kmlFile = File(downloadsDir, fileName)
|
||||
|
||||
try {
|
||||
val fos = FileOutputStream(kmlFile)
|
||||
fos.write(string.toByteArray())
|
||||
fos.close()
|
||||
return true
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private val isExternalStorageWritable: Boolean
|
||||
get() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue