mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Convert BookmarkItemsFragment to kotlin
This commit is contained in:
parent
c0514798c8
commit
30808d0bee
3 changed files with 63 additions and 82 deletions
|
|
@ -1,81 +0,0 @@
|
|||
package fr.free.nrw.commons.bookmarks.items;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksItemsBinding;
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Tab fragment to show list of bookmarked Wikidata Items
|
||||
*/
|
||||
public class BookmarkItemsFragment extends DaggerFragment {
|
||||
|
||||
private FragmentBookmarksItemsBinding binding;
|
||||
|
||||
@Inject
|
||||
BookmarkItemsController controller;
|
||||
|
||||
public static BookmarkItemsFragment newInstance() {
|
||||
return new BookmarkItemsFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
@NonNull final LayoutInflater inflater,
|
||||
final ViewGroup container,
|
||||
final Bundle savedInstanceState
|
||||
) {
|
||||
binding = FragmentBookmarksItemsBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(final @NotNull View view, @Nullable final Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
initList(requireContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initList(requireContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of DepictedItem and sets to the adapter
|
||||
* @param context context
|
||||
*/
|
||||
private void initList(final Context context) {
|
||||
final List<DepictedItem> depictItems = controller.loadFavoritesItems();
|
||||
final BookmarkItemsAdapter adapter = new BookmarkItemsAdapter(depictItems, context);
|
||||
binding.listView.setAdapter(adapter);
|
||||
binding.loadingImagesProgressBar.setVisibility(View.GONE);
|
||||
if (depictItems.isEmpty()) {
|
||||
binding.statusMessage.setText(R.string.bookmark_empty);
|
||||
binding.statusMessage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.statusMessage.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package fr.free.nrw.commons.bookmarks.items
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import dagger.android.support.DaggerFragment
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksItemsBinding
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Tab fragment to show list of bookmarked Wikidata Items
|
||||
*/
|
||||
class BookmarkItemsFragment : DaggerFragment() {
|
||||
private var binding: FragmentBookmarksItemsBinding? = null
|
||||
|
||||
@JvmField
|
||||
@Inject
|
||||
var controller: BookmarkItemsController? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
binding = FragmentBookmarksItemsBinding.inflate(inflater, container, false)
|
||||
return binding!!.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initList(requireContext())
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
initList(requireContext())
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of DepictedItem and sets to the adapter
|
||||
* @param context context
|
||||
*/
|
||||
private fun initList(context: Context) {
|
||||
val depictItems = controller!!.loadFavoritesItems()
|
||||
binding!!.listView.adapter = BookmarkItemsAdapter(depictItems, context)
|
||||
binding!!.loadingImagesProgressBar.visibility = View.GONE
|
||||
if (depictItems.isEmpty()) {
|
||||
binding!!.statusMessage.setText(R.string.bookmark_empty)
|
||||
binding!!.statusMessage.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding!!.statusMessage.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ class BookmarkItemsFragmentUnitTest {
|
|||
context = ApplicationProvider.getApplicationContext()
|
||||
OkHttpConnectionFactory.CLIENT = createTestClient()
|
||||
val activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
|
||||
fragment = BookmarkItemsFragment.newInstance()
|
||||
fragment = BookmarkItemsFragment()
|
||||
val fragmentManager: FragmentManager = activity.supportFragmentManager
|
||||
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
|
||||
fragmentTransaction.add(fragment, null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue