Code cleanup

This commit is contained in:
neslihanturan 2019-09-15 12:41:45 +03:00
parent 62eba391da
commit 7659aec94a
11 changed files with 7 additions and 443 deletions

View file

@ -146,12 +146,6 @@
android:name=".nearby.NearbyTestFragmentActivity"
android:label="@string/title_activity_nearby_test_fragment" />
<activity
android:name=".nearby.NearbyTestFragmentLayersActivity"
android:label="@string/title_activity_nearby_test_fragment_layers" />
<service android:name=".upload.UploadService" />
<service

View file

@ -49,7 +49,6 @@ import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.explore.categories.ExploreActivity;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.nearby.NearbyTestFragmentLayersActivity;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.ConfigUtils;
import fr.free.nrw.commons.utils.ViewUtil;

View file

@ -16,7 +16,6 @@ import fr.free.nrw.commons.explore.SearchActivity;
import fr.free.nrw.commons.explore.categories.ExploreActivity;
import fr.free.nrw.commons.nearby.NearbyTestActivity;
import fr.free.nrw.commons.nearby.NearbyTestFragmentActivity;
import fr.free.nrw.commons.nearby.NearbyTestFragmentLayersActivity;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.review.ReviewActivity;
import fr.free.nrw.commons.settings.SettingsActivity;
@ -76,7 +75,4 @@ public abstract class ActivityBuilderModule {
@ContributesAndroidInjector
abstract NearbyTestFragmentActivity bindNearbyTestFragment();
@ContributesAndroidInjector
abstract NearbyTestFragmentLayersActivity bindNearbyTestFragmentLayersActivity();
}

View file

@ -1,256 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.contributions.ContributionsFragment;
import fr.free.nrw.commons.contributions.UnswipableViewPager;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.upload.UploadService;
import timber.log.Timber;
import static android.content.ContentResolver.requestSync;
public class NearbyTestFragmentLayersActivity extends AuthenticatedActivity implements FragmentManager.OnBackStackChangedListener {
@Inject
public SessionManager sessionManager;
@BindView(R.id.tab_layout)
TabLayout tabLayout;
@BindView(R.id.pager)
public UnswipableViewPager viewPager;
public static final int CONTRIBUTIONS_TAB_POSITION = 0;
public static final int NEARBY_TAB_POSITION = 1;
public Intent uploadServiceIntent;
public boolean isAuthCookieAcquired = false;
public ContributionsActivityPagerAdapter contributionsActivityPagerAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nearby_test_fragment_layers);
ButterKnife.bind(this);
requestAuthToken();
initDrawer();
setTitle(getString(R.string.navigation_item_home)+"2"); // Should I create a new string variable with another name instead?
}
@Override
protected void onAuthCookieAcquired(String authCookie) {
// Do a sync everytime we get here!
requestSync(sessionManager.getCurrentAccount(), BuildConfig.CONTRIBUTION_AUTHORITY, new Bundle());
uploadServiceIntent = new Intent(this, UploadService.class);
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
startService(uploadServiceIntent);
addTabsAndFragments();
isAuthCookieAcquired = true;
if (contributionsActivityPagerAdapter.getItem(0) != null) {
((ContributionsFragment)contributionsActivityPagerAdapter.getItem(0)).onAuthCookieAcquired(uploadServiceIntent);
}
}
@Override
protected void onAuthFailure() {
}
private void addTabsAndFragments() {
contributionsActivityPagerAdapter = new ContributionsActivityPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(contributionsActivityPagerAdapter);
tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.contributions_fragment)));
tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.nearby_fragment)));
// Set custom view to add nearby info icon next to text
View nearbyTabLinearLayout = LayoutInflater.from(this).inflate(R.layout.custom_nearby_tab_layout, null);
tabLayout.getTabAt(1).setCustomView(nearbyTabLinearLayout);
setTabAndViewPagerSynchronisation();
}
private void setTabAndViewPagerSynchronisation() {
//viewPager.canScrollHorizontally(false);
viewPager.setFocusableInTouchMode(true);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
switch (position) {
case CONTRIBUTIONS_TAB_POSITION:
Timber.d("Contributions tab selected");
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
break;
case NEARBY_TAB_POSITION:
Timber.d("Nearby tab selected");
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
((NearbyTestLayersFragment)contributionsActivityPagerAdapter.getItem(1)).nearbyParentFragmentPresenter.onTabSelected();
break;
default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
@Override
public void onBackStackChanged() {
}
public class ContributionsActivityPagerAdapter extends FragmentPagerAdapter {
FragmentManager fragmentManager;
private boolean isContributionsListFragment = true; // to know what to put in first tab, Contributions of Media Details
public ContributionsActivityPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
this.fragmentManager = fragmentManager;
}
@Override
public int getCount() {
return 2;
}
/*
* Do not use getItem method to access fragments on pager adapter. User reference variables
* instead.
* */
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
ContributionsFragment retainedContributionsFragment = getContributionsFragment(0);
if (retainedContributionsFragment != null) {
return retainedContributionsFragment;
} else {
// If we reach here, retainedContributionsFragment is null
return new ContributionsFragment();
}
case 1:
NearbyTestLayersFragment retainedNearbyFragment = getNearbyFragment(1);
if (retainedNearbyFragment != null) {
return retainedNearbyFragment;
} else {
// If we reach here, retainedNearbyFragment is null
return new NearbyTestLayersFragment();
}
default:
return null;
}
}
/**
* Generates fragment tag with makeFragmentName method to get retained contributions fragment
* @param position index of tabs, in our case 0 or 1
* @return
*/
private ContributionsFragment getContributionsFragment(int position) {
String tag = makeFragmentName(R.id.pager, position);
return (ContributionsFragment)fragmentManager.findFragmentByTag(tag);
}
/**
* Generates fragment tag with makeFragmentName method to get retained nearby fragment
* @param position index of tabs, in our case 0 or 1
* @return
*/
private NearbyTestLayersFragment getNearbyFragment(int position) {
String tag = makeFragmentName(R.id.pager, position);
return (NearbyTestLayersFragment)fragmentManager.findFragmentByTag(tag);
}
/**
* A simple hack to use retained fragment when getID is called explicitly, if we don't use
* this method, a new fragment will be initialized on each explicit calls of getID
* @param viewId id of view pager
* @param index index of tabs, in our case 0 or 1
* @return
*/
public String makeFragmentName(int viewId, int index) {
return "android:switcher:" + viewId + ":" + index;
}
}
public void hideTabs() {
changeDrawerIconToBackButton();
if (tabLayout != null) {
tabLayout.setVisibility(View.GONE);
}
}
public void showTabs() {
changeDrawerIconToDefault();
if (tabLayout != null) {
tabLayout.setVisibility(View.VISIBLE);
}
}
/**
* Adds number of uploads next to tab text "Contributions" then it will look like
* "Contributions (NUMBER)"
* @param uploadCount
*/
public void setNumOfUploads(int uploadCount) {
tabLayout.getTabAt(0).setText(getResources().getString(R.string.contributions_fragment) +" "+ getResources()
.getQuantityString(R.plurals.contributions_subtitle,
uploadCount, uploadCount));
}
}

View file

@ -182,7 +182,6 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
View view;
public NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
SupportMapFragment mapFragment;
boolean isDarkTheme;
boolean isFabOpen;
boolean isBottomListSheetExpanded;
@ -192,6 +191,8 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
SupportMapFragment mapFragment;
private fr.free.nrw.commons.nearby.NearbyListFragment nearbyListFragment;
private static final String TAG_RETAINED_MAP_FRAGMENT = com.mapbox.mapboxsdk.maps.SupportMapFragment.class.getSimpleName();
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
@ -630,7 +631,7 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION,
runnable,
() -> ((NearbyTestFragmentLayersActivity) getActivity()).viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION),
() -> ((MainActivity) getActivity()).viewPager.setCurrentItem(CONTRIBUTIONS_TAB_POSITION),
R.string.location_permission_title,
R.string.location_permission_rationale_nearby);
}

View file

@ -1,18 +0,0 @@
package fr.free.nrw.commons.nearby.mvp.contract;
/**
* This interface defines specific View and UserActions for list
* part of the nearby. On the other hand both extends methods
* from parent View and UserActions where general methods are
* defined (in Nearby Contract)
*/
public interface NearbyListContract {
interface View extends NearbyElementContract.View {
// Even if this is empty for now, I keep this one for code consistency
}
interface UserActions extends NearbyElementContract.UserActions {
void expandItem();
}
}

View file

@ -1,11 +0,0 @@
package fr.free.nrw.commons.nearby.mvp.fragments;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyListContract;
public class NearbyListFragment extends CommonsDaggerSupportFragment implements NearbyListContract.View {
@Override
public void showPlaces() {
}
}

View file

@ -42,6 +42,7 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.NearbyListFragment;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
import fr.free.nrw.commons.utils.FragmentUtils;

View file

@ -1,51 +0,0 @@
package fr.free.nrw.commons.nearby.mvp.presenter;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyListContract;
public class NearbyListPresenter implements NearbyListContract.UserActions {
@Override
public void expandItem() {
}
@Override
public void uploadImageGallery() {
}
@Override
public void uploadImageCamera() {
}
@Override
public void bookmarkItem() {
}
@Override
public void getDirections() {
}
@Override
public void seeWikidataItem() {
}
@Override
public void seeWikipediaArticle() {
}
@Override
public void seeCommonsFilePage() {
}
@Override
public void rotateScreen() {
}
}

View file

@ -1,88 +0,0 @@
package fr.free.nrw.commons.nearby.mvp.presenter;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
public class NearbyMapPresenter implements NearbyMapContract.UserActions {
NearbyMapContract.View nearbyMapFragmentView;
void NearbyMapPresenter(NearbyMapContract.View nearbyMapFragmentView) {
this.nearbyMapFragmentView = nearbyMapFragmentView;
}
@Override
public void searchThisArea() {
}
@Override
public void storeSharedPrefs() {
}
@Override
public void recenterMap() {
}
@Override
public void updateMapMarkers(LatLng latLng) {
}
public void updateMapMarkers() {
}
@Override
public void updateMapToTrackPosition() {
}
@Override
public void getBundleContent() {
}
@Override
public void uploadImageGallery() {
}
@Override
public void uploadImageCamera() {
}
@Override
public void bookmarkItem() {
}
@Override
public void getDirections() {
}
@Override
public void seeWikidataItem() {
}
@Override
public void seeWikipediaArticle() {
}
@Override
public void seeCommonsFilePage() {
}
@Override
public void rotateScreen() {
}
}

View file

@ -38,9 +38,6 @@ import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.explore.categories.ExploreActivity;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.logging.CommonsLogSender;
import fr.free.nrw.commons.nearby.NearbyTestActivity;
import fr.free.nrw.commons.nearby.NearbyTestFragmentActivity;
import fr.free.nrw.commons.nearby.NearbyTestFragmentLayersActivity;
import fr.free.nrw.commons.review.ReviewActivity;
import fr.free.nrw.commons.settings.SettingsActivity;
import timber.log.Timber;
@ -181,17 +178,17 @@ public abstract class NavigationBaseActivity extends BaseActivity
return true;
case R.id.action_nearby_test_activity:
drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(this, NearbyTestActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
startActivityWithFlags(this, MainActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
Intent.FLAG_ACTIVITY_SINGLE_TOP);
return true;
case R.id.action_nearby_test_fragment:
drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(this, NearbyTestFragmentActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
startActivityWithFlags(this, MainActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
Intent.FLAG_ACTIVITY_SINGLE_TOP);
return true;
case R.id.action_nearby_test_fragment_layers:
drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(this, NearbyTestFragmentLayersActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
startActivityWithFlags(this, MainActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
Intent.FLAG_ACTIVITY_SINGLE_TOP);
return true;
case R.id.action_feedback: