use of fr.free.nrw.commons.contributions.MainActivity in project apps-android-commons by commons-app.
the class MediaDetailPagerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_media_detail_pager, container, false);
ButterKnife.bind(this, view);
pager.addOnPageChangeListener(this);
adapter = new MediaDetailAdapter(getChildFragmentManager());
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getActivity() != null) {
final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
pager.setAdapter(adapter);
if (savedInstanceState != null) {
final int pageNumber = savedInstanceState.getInt("current-page");
pager.setCurrentItem(pageNumber, false);
getActivity().invalidateOptionsMenu();
}
adapter.notifyDataSetChanged();
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).hideTabs();
}
return view;
}
use of fr.free.nrw.commons.contributions.MainActivity in project apps-android-commons by commons-app.
the class SettingsFragment method prepareAppLanguages.
/**
* Prepare and Show language selection dialog box
* Uses previously saved language if there is any, if not uses phone locale as initial language.
* Disable default/already selected language from dialog box
* Get ListPreference key and act accordingly for each ListPreference.
* saves value chosen by user to shared preferences
* to remember later and recall MainActivity to reflect language changes
* @param keyListPreference
*/
private void prepareAppLanguages(final String keyListPreference) {
// Gets current language code from shared preferences
final String languageCode = getCurrentLanguageCode(keyListPreference);
HashMap<Integer, String> selectedLanguages = new HashMap<>();
if (keyListPreference.equals("appUiDefaultLanguagePref")) {
assert languageCode != null;
if (languageCode.equals("")) {
selectedLanguages.put(0, Locale.getDefault().getLanguage());
} else {
selectedLanguages.put(0, languageCode);
}
} else if (keyListPreference.equals("descriptionDefaultLanguagePref")) {
assert languageCode != null;
if (languageCode.equals("")) {
selectedLanguages.put(0, Locale.getDefault().getLanguage());
} else {
selectedLanguages.put(0, languageCode);
}
}
LanguagesAdapter languagesAdapter = new LanguagesAdapter(getActivity(), selectedLanguages);
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.dialog_select_language);
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setLayout((int) (getActivity().getResources().getDisplayMetrics().widthPixels * 0.90), (int) (getActivity().getResources().getDisplayMetrics().heightPixels * 0.90));
dialog.show();
EditText editText = dialog.findViewById(R.id.search_language);
ListView listView = dialog.findViewById(R.id.language_list);
listView.setAdapter(languagesAdapter);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
languagesAdapter.getFilter().filter(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String languageCode = ((LanguagesAdapter) adapterView.getAdapter()).getLanguageCode(i);
saveLanguageValue(languageCode, keyListPreference);
Locale defLocale = new Locale(languageCode);
if (keyListPreference.equals("appUiDefaultLanguagePref")) {
appUiLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
setLocale(Objects.requireNonNull(getActivity()), languageCode);
getActivity().recreate();
final Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
} else {
descriptionLanguageListPreference.setSummary(defLocale.getDisplayLanguage(defLocale));
}
dialog.dismiss();
}
});
dialog.setOnDismissListener(dialogInterface -> languagesAdapter.getFilter().filter(""));
}
use of fr.free.nrw.commons.contributions.MainActivity in project apps-android-commons by commons-app.
the class CampaignView method init.
private void init() {
final View rootView = inflate(getContext(), R.layout.layout_campagin, this);
viewHolder = new ViewHolder(rootView);
setOnClickListener(view -> {
if (campaign != null) {
if (campaign.isWLMCampaign()) {
((MainActivity) (getContext())).showNearby();
} else {
Utils.handleWebUrl(getContext(), Uri.parse(campaign.getLink()));
}
}
});
}
use of fr.free.nrw.commons.contributions.MainActivity in project apps-android-commons by commons-app.
the class BookmarkListRootFragment method backPressed.
public boolean backPressed() {
// check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
if (mediaDetails != null) {
if (mediaDetails.isVisible()) {
if (mediaDetails.backButtonClicked()) {
// mediaDetails handled the back clicked , no further action required.
return true;
}
// todo add get list fragment
((BookmarkFragment) getParentFragment()).setupTabLayout();
ArrayList<Integer> removed = mediaDetails.getRemovedItems();
removeFragment(mediaDetails);
((BookmarkFragment) getParentFragment()).setScroll(true);
setFragment(listFragment, mediaDetails);
((MainActivity) getActivity()).showTabs();
if (listFragment instanceof BookmarkPicturesFragment) {
GridViewAdapter adapter = ((GridViewAdapter) ((BookmarkPicturesFragment) listFragment).getAdapter());
Iterator i = removed.iterator();
while (i.hasNext()) {
adapter.remove(adapter.getItem((int) i.next()));
}
mediaDetails.clearRemoved();
}
} else {
moveToContributionsFragment();
}
} else {
moveToContributionsFragment();
}
// notify mediaDetails did not handled the backPressed further actions required.
return false;
}
use of fr.free.nrw.commons.contributions.MainActivity in project apps-android-commons by commons-app.
the class BookmarkFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_bookmarks, container, false);
ButterKnife.bind(this, view);
// Activity can call methods in the fragment by acquiring a
// reference to the Fragment from FragmentManager, using findFragmentById()
supportFragmentManager = getChildFragmentManager();
adapter = new BookmarksPagerAdapter(supportFragmentManager, getContext(), applicationKvStore.getBoolean("login_skipped"));
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
((MainActivity) getActivity()).showTabs();
((BaseActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
setupTabLayout();
return view;
}
Aggregations