forked from organicmaps/organicmaps
[android] Fixed review notes - moved observable to mwmApp
This commit is contained in:
parent
03ea9671da
commit
59c5d18a42
9 changed files with 57 additions and 72 deletions
|
@ -105,7 +105,7 @@
|
|||
android:id="@+id/download_routers_btn"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
style="@style/MwmWidget.Button.Primary"
|
||||
android:layout_weight="0"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:text="@string/download_guides"
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme"/>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:scrollbars="none"
|
||||
android:fillViewport="true"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -59,7 +58,7 @@
|
|||
android:layout_height="@dimen/margin_base_plus"/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:background="@color/black_38"
|
||||
android:background="?attr/iconTintDisabled"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/divider_height"/>
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.mapswithme.maps.background.NotificationChannelFactory;
|
|||
import com.mapswithme.maps.background.NotificationChannelProvider;
|
||||
import com.mapswithme.maps.background.Notifier;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.content.BookmarkCategoryObservable;
|
||||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
|
@ -73,12 +74,22 @@ public class MwmApplication extends Application
|
|||
@NonNull
|
||||
private ExternalLibrariesMediator mMediator;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BookmarkCategoryObservable mBookmarkCategoryObservable;
|
||||
|
||||
@NonNull
|
||||
public SubwayManager getSubwayManager()
|
||||
{
|
||||
return mSubwayManager;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategoryObservable getBookmarkCategoryObservable()
|
||||
{
|
||||
return mBookmarkCategoryObservable;
|
||||
}
|
||||
|
||||
public MwmApplication()
|
||||
{
|
||||
super();
|
||||
|
@ -134,6 +145,7 @@ public class MwmApplication extends Application
|
|||
mMediator.initSensitiveDataToleranceLibraries();
|
||||
mMediator.initSensitiveDataStrictLibrariesAsync();
|
||||
Statistics.INSTANCE.setMediator(mMediator);
|
||||
initAppComponents();
|
||||
|
||||
mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
|
||||
initNotificationChannels();
|
||||
|
@ -145,6 +157,11 @@ public class MwmApplication extends Application
|
|||
mConnectivityListener.listen();
|
||||
}
|
||||
|
||||
private void initAppComponents()
|
||||
{
|
||||
mBookmarkCategoryObservable = new BookmarkCategoryObservable();
|
||||
}
|
||||
|
||||
private void initNotificationChannels()
|
||||
{
|
||||
NotificationChannelProvider channelProvider = NotificationChannelFactory.createProvider(this);
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.mapswithme.maps.base;
|
||||
|
||||
import android.database.Observable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
public class DataObservable extends Observable<RecyclerView.AdapterDataObserver>
|
||||
{
|
||||
public void notifyChanged() {
|
||||
for (int i = mObservers.size() - 1; i >= 0; i--) {
|
||||
mObservers.get(i).onChanged();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.mapswithme.maps.base;
|
||||
|
||||
import android.database.Observable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
public interface ObservableHost<T extends Observable<RecyclerView.AdapterDataObserver>>
|
||||
{
|
||||
@NonNull
|
||||
T getObservable();
|
||||
}
|
|
@ -338,7 +338,7 @@ public enum BookmarkManager
|
|||
nativeSetCategoryName(catId, name);
|
||||
}
|
||||
|
||||
public void setCategoryDesc(long id, @NonNull String categoryDesc)
|
||||
public void setCategoryDescription(long id, @NonNull String categoryDesc)
|
||||
{
|
||||
nativeSetCategoryDescription(id, categoryDesc);
|
||||
}
|
||||
|
@ -658,7 +658,7 @@ public enum BookmarkManager
|
|||
|
||||
private native void nativeSetCategoryName(long catId, @NonNull String n);
|
||||
|
||||
private native void nativeSetCategoryDescription(long catId, @NonNull String n);
|
||||
private native void nativeSetCategoryDescription(long catId, @NonNull String desc);
|
||||
|
||||
private native void nativeSetCategoryTags(long catId, @NonNull String[] tagsIds);
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.mapswithme.maps.content;
|
||||
|
||||
import android.app.Application;
|
||||
import android.database.Observable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
||||
public class BookmarkCategoryObservable extends Observable<RecyclerView.AdapterDataObserver>
|
||||
{
|
||||
public void notifyChanged()
|
||||
{
|
||||
for (int i = mObservers.size() - 1; i >= 0; i--)
|
||||
{
|
||||
mObservers.get(i).onChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static BookmarkCategoryObservable from(@NonNull Application app)
|
||||
{
|
||||
MwmApplication mwmApplication = (MwmApplication) app;
|
||||
return mwmApplication.getBookmarkCategoryObservable();
|
||||
}
|
||||
}
|
|
@ -1,32 +1,24 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.DataObservable;
|
||||
import com.mapswithme.maps.base.ObservableHost;
|
||||
|
||||
public class UgcRouteEditSettingsActivity extends BaseMwmFragmentActivity implements ObservableHost<DataObservable>
|
||||
public class UgcRouteEditSettingsActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
public static final String EXTRA_BOOKMARK_CATEGORY = "bookmark_category";
|
||||
|
||||
private static final String FRAGMENT_TAG = "edit_settings_fragment_tag";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private DataObservable mObservable;
|
||||
|
||||
@Override
|
||||
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.safeOnCreate(savedInstanceState);
|
||||
setContentView(R.layout.ugc_route_edit_settings_activity);
|
||||
mObservable = new DataObservable();
|
||||
addSettingsFragmentIfAbsent();
|
||||
}
|
||||
|
||||
|
@ -47,11 +39,4 @@ public class UgcRouteEditSettingsActivity extends BaseMwmFragmentActivity implem
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DataObservable getObservable()
|
||||
{
|
||||
return mObservable;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -16,18 +15,15 @@ import android.widget.TextView;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.maps.base.DataObservable;
|
||||
import com.mapswithme.maps.base.ObservableHost;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.content.BookmarkCategoryObservable;
|
||||
import com.mapswithme.maps.widget.ToolbarController;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
||||
{
|
||||
private static final String SHARING_OPTIONS_FRAGMENT_TAG = "sharing_options_fragment";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BookmarkCategory mCategory;
|
||||
|
@ -40,10 +36,6 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
@NonNull
|
||||
private TextView mAccessRulesView;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private ObservableHost<DataObservable> mObserverHost;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private EditText mEditDescView;
|
||||
|
@ -52,13 +44,6 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
@NonNull
|
||||
private EditText mEditCategoryNameView;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
mObserverHost = (ObservableHost<DataObservable>) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -77,13 +62,12 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
View root = inflater.inflate(R.layout.fragment_ugc_route_edit, container, false);
|
||||
initViews(root);
|
||||
mObserver = new CategoryObserver();
|
||||
mObserverHost.getObservable().registerObserver(mObserver);
|
||||
BookmarkCategoryObservable.from(getActivity().getApplication()).registerObserver(mObserver);
|
||||
return root;
|
||||
}
|
||||
|
||||
private void initViews(@NonNull View root)
|
||||
{
|
||||
View sharingOptionsBtn = root.findViewById(R.id.open_sharing_options_screen_btn_container);
|
||||
mEditCategoryNameView = root.findViewById(R.id.edit_category_name_view);
|
||||
mEditCategoryNameView.setText(mCategory.getName());
|
||||
mEditCategoryNameView.requestFocus();
|
||||
|
@ -93,6 +77,7 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
mEditDescView.setText(mCategory.getDescription());
|
||||
View clearNameBtn = root.findViewById(R.id.edit_text_clear_btn);
|
||||
clearNameBtn.setOnClickListener(v -> mEditCategoryNameView.getEditableText().clear());
|
||||
View sharingOptionsBtn = root.findViewById(R.id.open_sharing_options_screen_btn_container);
|
||||
sharingOptionsBtn.setOnClickListener(v -> onSharingOptionsClicked());
|
||||
}
|
||||
|
||||
|
@ -100,7 +85,7 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
public void onDestroyView()
|
||||
{
|
||||
super.onDestroyView();
|
||||
mObserverHost.getObservable().unregisterObserver(mObserver);
|
||||
BookmarkCategoryObservable.from(getActivity().getApplication()).unregisterObserver(mObserver);
|
||||
}
|
||||
|
||||
private void onSharingOptionsClicked()
|
||||
|
@ -110,12 +95,9 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
|
||||
private void openSharingOptionsScreen()
|
||||
{
|
||||
Fragment fragment = UgcSharingOptionsFragment.makeInstance(mCategory);
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, fragment, SHARING_OPTIONS_FRAGMENT_TAG)
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
Intent intent = new Intent(getContext(), UgcRouteSharingOptionsActivity.class)
|
||||
.putExtra(UgcSharingOptionsFragment.EXTRA_BOOKMARK_CATEGORY, mCategory);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,7 +134,7 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
|
||||
String categoryDesc = mEditDescView.getEditableText().toString().trim();
|
||||
if (!TextUtils.equals(mCategory.getDescription(), categoryDesc))
|
||||
BookmarkManager.INSTANCE.setCategoryDesc(mCategory.getId(), categoryDesc);
|
||||
BookmarkManager.INSTANCE.setCategoryDescription(mCategory.getId(), categoryDesc);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue