Skip to content

Commit 8de5730

Browse files
authored
Convert bookmarks package to kotlin (#6387)
* Convert BookmarkItemsController to kotlin * Split BookmarkItemsDao apart and converted to Kotlin * Convert and cleanup content providers * Convert BookmarkItemsFragment to kotlin * Convert BookmarkPicturesFragment to kotlin * Convert BookmarkPicturesDao to kotlin and share some useful DB methods * Convert BookmarkPicturesController to kotlin * Convert BookmarkFragment to kotlin * Convert BookmarksPagerAdapter to kotlin * Convert BookmarkListRootFragment to kotlin
1 parent 869371b commit 8de5730

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1738
-1988
lines changed

app/src/main/java/fr/free/nrw/commons/CommonsApplication.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import com.facebook.drawee.backends.pipeline.Fresco
1515
import com.facebook.imagepipeline.core.ImagePipelineConfig
1616
import fr.free.nrw.commons.auth.LoginActivity
1717
import fr.free.nrw.commons.auth.SessionManager
18-
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao
19-
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
20-
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao
18+
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsTable
19+
import fr.free.nrw.commons.bookmarks.pictures.BookmarksTable
2120
import fr.free.nrw.commons.category.CategoryDao
2221
import fr.free.nrw.commons.concurrency.BackgroundPoolExceptionHandler
2322
import fr.free.nrw.commons.concurrency.ThreadPoolService
@@ -257,8 +256,8 @@ class CommonsApplication : MultiDexApplication() {
257256
} catch (e: SQLiteException) {
258257
Timber.e(e)
259258
}
260-
BookmarkPicturesDao.Table.onDelete(db)
261-
BookmarkItemsDao.Table.onDelete(db)
259+
BookmarksTable.onDelete(db)
260+
BookmarkItemsTable.onDelete(db)
262261
}
263262

264263

app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkFragment.java

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package fr.free.nrw.commons.bookmarks
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import fr.free.nrw.commons.contributions.ContributionController
8+
import fr.free.nrw.commons.contributions.MainActivity
9+
import fr.free.nrw.commons.databinding.FragmentBookmarksBinding
10+
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
11+
import fr.free.nrw.commons.kvstore.JsonKvStore
12+
import fr.free.nrw.commons.theme.BaseActivity
13+
import javax.inject.Inject
14+
import javax.inject.Named
15+
16+
class BookmarkFragment : CommonsDaggerSupportFragment() {
17+
private var adapter: BookmarksPagerAdapter? = null
18+
19+
@JvmField
20+
var binding: FragmentBookmarksBinding? = null
21+
22+
@JvmField
23+
@Inject
24+
var controller: ContributionController? = null
25+
26+
/**
27+
* To check if the user is loggedIn or not.
28+
*/
29+
@JvmField
30+
@Inject
31+
@Named("default_preferences")
32+
var applicationKvStore: JsonKvStore? = null
33+
34+
fun setScroll(canScroll: Boolean) {
35+
binding?.let {
36+
it.viewPagerBookmarks.isCanScroll = canScroll
37+
}
38+
}
39+
40+
override fun onCreateView(
41+
inflater: LayoutInflater,
42+
container: ViewGroup?,
43+
savedInstanceState: Bundle?
44+
): View {
45+
super.onCreateView(inflater, container, savedInstanceState)
46+
binding = FragmentBookmarksBinding.inflate(inflater, container, false)
47+
48+
// Activity can call methods in the fragment by acquiring a
49+
// reference to the Fragment from FragmentManager, using findFragmentById()
50+
val supportFragmentManager = childFragmentManager
51+
52+
adapter = BookmarksPagerAdapter(
53+
supportFragmentManager, requireContext(),
54+
applicationKvStore!!.getBoolean("login_skipped")
55+
)
56+
binding!!.viewPagerBookmarks.adapter = adapter
57+
binding!!.tabLayout.setupWithViewPager(binding!!.viewPagerBookmarks)
58+
59+
(requireActivity() as MainActivity).showTabs()
60+
(requireActivity() as BaseActivity).supportActionBar!!.setDisplayHomeAsUpEnabled(false)
61+
62+
setupTabLayout()
63+
return binding!!.root
64+
}
65+
66+
/**
67+
* This method sets up the tab layout. If the adapter has only one element it sets the
68+
* visibility of tabLayout to gone.
69+
*/
70+
fun setupTabLayout() {
71+
binding!!.tabLayout.visibility = View.VISIBLE
72+
if (adapter!!.count == 1) {
73+
binding!!.tabLayout.visibility = View.GONE
74+
}
75+
}
76+
77+
78+
fun onBackPressed() {
79+
if (((adapter!!.getItem(binding!!.tabLayout.selectedTabPosition)) as BookmarkListRootFragment).backPressed()) {
80+
// The event is handled internally by the adapter , no further action required.
81+
return
82+
}
83+
84+
// Event is not handled by the adapter ( performed back action ) change action bar.
85+
(requireActivity() as BaseActivity).supportActionBar!!.setDisplayHomeAsUpEnabled(false)
86+
}
87+
88+
override fun onDestroy() {
89+
super.onDestroy()
90+
binding = null
91+
}
92+
93+
companion object {
94+
fun newInstance(): BookmarkFragment = BookmarkFragment().apply {
95+
retainInstance = true
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)