mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Enable support toolbar for ProfileActivity and added a couple of unit… (#5188)
* Enable support toolbar for ProfileActivity and added a couple of unit tests * Nit fixes * Nit Fixes * Minor styling changes in ContributionsFragment
This commit is contained in:
parent
fc672dbd9b
commit
07616485ae
7 changed files with 97 additions and 50 deletions
|
|
@ -196,6 +196,10 @@ public class ContributionsFragment
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
|
||||
|
||||
// Removing contributions menu items for ProfileActivity
|
||||
if (getActivity() instanceof ProfileActivity) { return; }
|
||||
|
||||
inflater.inflate(R.menu.contribution_activity_notification_menu, menu);
|
||||
|
||||
MenuItem notificationsMenuItem = menu.findItem(R.id.notifications);
|
||||
|
|
@ -339,23 +343,23 @@ public class ContributionsFragment
|
|||
if (fragment.isAdded() && otherFragment != null) {
|
||||
transaction.hide(otherFragment);
|
||||
transaction.show(fragment);
|
||||
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
|
||||
transaction.addToBackStack(tag);
|
||||
transaction.commit();
|
||||
getChildFragmentManager().executePendingTransactions();
|
||||
} else if (fragment.isAdded() && otherFragment == null) {
|
||||
transaction.show(fragment);
|
||||
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
|
||||
transaction.addToBackStack(tag);
|
||||
transaction.commit();
|
||||
getChildFragmentManager().executePendingTransactions();
|
||||
}else if (!fragment.isAdded() && otherFragment != null ) {
|
||||
transaction.hide(otherFragment);
|
||||
transaction.add(R.id.root_frame, fragment, tag);
|
||||
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
|
||||
transaction.addToBackStack(tag);
|
||||
transaction.commit();
|
||||
getChildFragmentManager().executePendingTransactions();
|
||||
} else if (!fragment.isAdded()) {
|
||||
transaction.replace(R.id.root_frame, fragment, tag);
|
||||
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
|
||||
transaction.addToBackStack(tag);
|
||||
transaction.commit();
|
||||
getChildFragmentManager().executePendingTransactions();
|
||||
}
|
||||
|
|
@ -641,7 +645,7 @@ public class ContributionsFragment
|
|||
@Override
|
||||
public void showDetail(int position, boolean isWikipediaButtonDisplayed) {
|
||||
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
|
||||
mediaDetailPagerFragment = new MediaDetailPagerFragment();
|
||||
mediaDetailPagerFragment = new MediaDetailPagerFragment(false, true);
|
||||
if(isUserProfile) {
|
||||
((ProfileActivity)getActivity()).setScroll(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,10 +78,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
return removedItems;
|
||||
}
|
||||
|
||||
public MediaDetailPagerFragment() {
|
||||
this(false, false);
|
||||
}
|
||||
|
||||
private MediaDetailPagerFragment() {}; // Constructor calls made to be explicit
|
||||
@SuppressLint("ValidFragment")
|
||||
public MediaDetailPagerFragment(Boolean editable, boolean isFeaturedImage) {
|
||||
this.editable = editable;
|
||||
|
|
@ -107,11 +104,13 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
|
||||
adapter = new MediaDetailAdapter(getChildFragmentManager());
|
||||
|
||||
if (getActivity() != null) {
|
||||
final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
// ActionBar is now supported in both activities - if this crashes something is quite wrong
|
||||
final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("Action bar should not be null!");
|
||||
}
|
||||
|
||||
// If fragment is associated with ProfileActivity, then hide the tabLayout
|
||||
|
|
@ -119,6 +118,11 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
((ProfileActivity)getActivity()).tabLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// Else if fragment is associated with MainActivity then hide that tab layout
|
||||
else if (getActivity() instanceof MainActivity) {
|
||||
((MainActivity)getActivity()).hideTabs();
|
||||
}
|
||||
|
||||
pager.setAdapter(adapter);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
|
|
@ -127,9 +131,7 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
|||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
if (getActivity() instanceof MainActivity) {
|
||||
((MainActivity)getActivity()).hideTabs();
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.view.View;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
|
@ -50,6 +51,9 @@ public class ProfileActivity extends BaseActivity {
|
|||
@BindView(R.id.tab_layout)
|
||||
public TabLayout tabLayout;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
|
||||
|
|
@ -83,9 +87,14 @@ public class ProfileActivity extends BaseActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_profile);
|
||||
ButterKnife.bind(this);
|
||||
setTitle(sessionManager.getUserName());
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationOnClickListener(view -> {
|
||||
onSupportNavigateUp();
|
||||
});
|
||||
|
||||
userName = getIntent().getStringExtra(KEY_USERNAME);
|
||||
setTitle(userName);
|
||||
shouldShowContributions = getIntent().getBooleanExtra(KEY_SHOULD_SHOW_CONTRIBUTIONS, false);
|
||||
|
||||
supportFragmentManager = getSupportFragmentManager();
|
||||
|
|
@ -140,14 +149,13 @@ public class ProfileActivity extends BaseActivity {
|
|||
fragmentList.add(leaderboardFragment);
|
||||
titleList.add(getResources().getString(R.string.leaderboard_tab_title).toUpperCase());
|
||||
|
||||
if (shouldShowContributions) {
|
||||
contributionsFragment = new ContributionsFragment();
|
||||
Bundle contributionsListBundle = new Bundle();
|
||||
contributionsListBundle.putString(KEY_USERNAME, userName);
|
||||
contributionsFragment.setArguments(contributionsListBundle);
|
||||
fragmentList.add(contributionsFragment);
|
||||
titleList.add(getString(R.string.contributions_fragment).toUpperCase());
|
||||
}
|
||||
contributionsFragment = new ContributionsFragment();
|
||||
Bundle contributionsListBundle = new Bundle();
|
||||
contributionsListBundle.putString(KEY_USERNAME, userName);
|
||||
contributionsFragment.setArguments(contributionsListBundle);
|
||||
fragmentList.add(contributionsFragment);
|
||||
titleList.add(getString(R.string.contributions_fragment).toUpperCase());
|
||||
|
||||
viewPagerAdapter.setTabData(fragmentList, titleList);
|
||||
viewPagerAdapter.notifyDataSetChanged();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,33 +5,44 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/toolbar_layout"
|
||||
<include
|
||||
layout="@layout/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/mainBackground">
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/toolbar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:background="?attr/tabBackground"
|
||||
app:tabIndicatorColor="?attr/tabIndicatorColor"
|
||||
app:tabMode="fixed"
|
||||
app:tabSelectedTextColor="?attr/tabSelectedTextColor"
|
||||
app:tabTextColor="?attr/tabTextColor" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
android:background="?attr/mainBackground">
|
||||
|
||||
<fr.free.nrw.commons.explore.ParentViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar_layout" />
|
||||
</RelativeLayout>
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:background="?attr/tabBackground"
|
||||
app:tabIndicatorColor="?attr/tabIndicatorColor"
|
||||
app:tabMode="fixed"
|
||||
app:tabSelectedTextColor="?attr/tabSelectedTextColor"
|
||||
app:tabTextColor="?attr/tabTextColor" />
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<fr.free.nrw.commons.explore.ParentViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar_layout" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
|
|
@ -48,13 +48,21 @@
|
|||
android:text="@string/limited_connection_explanation"/>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/explore_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="visible">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/root_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/miniscule_margin"
|
||||
android:background="#000"
|
||||
>
|
||||
android:background="#000">
|
||||
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -67,7 +67,7 @@ class MediaDetailPagerFragmentUnitTests {
|
|||
|
||||
val activity = Robolectric.buildActivity(SearchActivity::class.java).create().get()
|
||||
|
||||
fragment = MediaDetailPagerFragment()
|
||||
fragment = MediaDetailPagerFragment(false, true)
|
||||
fragment = MediaDetailPagerFragment(false, false)
|
||||
fragment = MediaDetailPagerFragment(false, false, 0)
|
||||
fragmentManager = activity.supportFragmentManager
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.graphics.Bitmap
|
|||
import android.os.Looper
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
|
|
@ -106,4 +107,17 @@ class ProfileActivityTest {
|
|||
fun testOnSupportNavigateUp() {
|
||||
activity.onSupportNavigateUp()
|
||||
}
|
||||
@Test
|
||||
fun testToolbarNotNull() {
|
||||
val toolbar = activity.findViewById<Toolbar>(R.id.toolbar)
|
||||
Assert.assertNotNull(toolbar)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOptionsMenu() {
|
||||
val menu: Menu = RoboMenu(mockContext)
|
||||
activity.onCreateOptionsMenu(menu)
|
||||
Assert.assertEquals(1, menu.size())
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue