mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Convert UploadBaseFragment to kotlin
This commit is contained in:
parent
798de8be71
commit
e3aac88f5b
4 changed files with 29 additions and 43 deletions
|
|
@ -1,41 +0,0 @@
|
||||||
package fr.free.nrw.commons.upload;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base fragment of the fragments in upload
|
|
||||||
*/
|
|
||||||
public class UploadBaseFragment extends CommonsDaggerSupportFragment {
|
|
||||||
|
|
||||||
public Callback callback;
|
|
||||||
public static final String CALLBACK = "callback";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(Callback callback) {
|
|
||||||
this.callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onBecameVisible() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Callback {
|
|
||||||
|
|
||||||
void onNextButtonClicked(int index);
|
|
||||||
|
|
||||||
void onPreviousButtonClicked(int index);
|
|
||||||
|
|
||||||
void showProgress(boolean shouldShow);
|
|
||||||
|
|
||||||
int getIndexInViewFlipper(UploadBaseFragment fragment);
|
|
||||||
|
|
||||||
int getTotalNumberOfSteps();
|
|
||||||
|
|
||||||
boolean isWLMUpload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base fragment of the fragments in upload
|
||||||
|
*/
|
||||||
|
abstract class UploadBaseFragment : CommonsDaggerSupportFragment() {
|
||||||
|
lateinit var callback: Callback
|
||||||
|
|
||||||
|
protected open fun onBecameVisible() = Unit
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
val totalNumberOfSteps: Int
|
||||||
|
val isWLMUpload: Boolean
|
||||||
|
|
||||||
|
fun onNextButtonClicked(index: Int)
|
||||||
|
fun onPreviousButtonClicked(index: Int)
|
||||||
|
fun showProgress(shouldShow: Boolean)
|
||||||
|
fun getIndexInViewFlipper(fragment: UploadBaseFragment?): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val CALLBACK: String = "callback"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -220,7 +220,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun goToNextScreen() {
|
override fun goToNextScreen() {
|
||||||
callback?.onNextButtonClicked(callback.getIndexInViewFlipper(this))
|
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showNoCategorySelected() {
|
override fun showNoCategorySelected() {
|
||||||
|
|
@ -322,7 +322,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
mediaDetailFragment.onResume()
|
mediaDetailFragment.onResume()
|
||||||
goBackToPreviousScreen()
|
goBackToPreviousScreen()
|
||||||
} else {
|
} else {
|
||||||
callback?.onPreviousButtonClicked(callback.getIndexInViewFlipper(this))
|
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ class UploadCategoriesFragmentUnitTests {
|
||||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||||
val activity = Robolectric.buildActivity(UploadActivity::class.java).create().get()
|
val activity = Robolectric.buildActivity(UploadActivity::class.java).create().get()
|
||||||
fragment = UploadCategoriesFragment()
|
fragment = UploadCategoriesFragment()
|
||||||
|
fragment.callback = callback
|
||||||
fragmentManager = activity.supportFragmentManager
|
fragmentManager = activity.supportFragmentManager
|
||||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||||
fragmentTransaction.add(fragment, null)
|
fragmentTransaction.add(fragment, null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue