Search in sources :

Example 1 with MainActivity

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;
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) MainActivity(fr.free.nrw.commons.contributions.MainActivity) BindView(butterknife.BindView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) SuppressLint(android.annotation.SuppressLint)

Example 2 with MainActivity

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(""));
}
Also used : EditText(android.widget.EditText) Locale(java.util.Locale) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) HashMap(java.util.HashMap) Intent(android.content.Intent) MainActivity(fr.free.nrw.commons.contributions.MainActivity) View(android.view.View) AdapterView(android.widget.AdapterView) CampaignView(fr.free.nrw.commons.campaigns.CampaignView) ListView(android.widget.ListView) LanguagesAdapter(fr.free.nrw.commons.upload.LanguagesAdapter) ListView(android.widget.ListView) Dialog(android.app.Dialog) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 3 with MainActivity

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()));
            }
        }
    });
}
Also used : MainActivity(fr.free.nrw.commons.contributions.MainActivity) ImageView(android.widget.ImageView) SwipableCardView(fr.free.nrw.commons.utils.SwipableCardView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View)

Example 4 with MainActivity

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;
}
Also used : GridViewAdapter(fr.free.nrw.commons.category.GridViewAdapter) Iterator(java.util.Iterator) MainActivity(fr.free.nrw.commons.contributions.MainActivity) BookmarkPicturesFragment(fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment)

Example 5 with MainActivity

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;
}
Also used : MainActivity(fr.free.nrw.commons.contributions.MainActivity) BindView(butterknife.BindView) View(android.view.View) Nullable(androidx.annotation.Nullable)

Aggregations

MainActivity (fr.free.nrw.commons.contributions.MainActivity)6 View (android.view.View)4 BindView (butterknife.BindView)3 SuppressLint (android.annotation.SuppressLint)1 Dialog (android.app.Dialog)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 ActionBar (androidx.appcompat.app.ActionBar)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 Fragment (androidx.fragment.app.Fragment)1 BookmarkPicturesFragment (fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment)1