Search in sources :

Example 1 with StructIGStickerGroup

use of net.iGap.fragments.emoji.struct.StructIGStickerGroup in project iGap-Android by KianIranian-STDG.

the class StickerSettingFragment method setupViews.

@Override
public void setupViews() {
    RecyclerView recyclerView = rootView.findViewById(R.id.rv_removeSticker);
    LinearLayout linearLayout = rootView.findViewById(R.id.ll_stickerSetting_toolBar);
    HelperToolbar helperToolbar = HelperToolbar.create().setLeftIcon(R.string.icon_back).setLogoShown(true).setDefaultTitle(getResources().getString(R.string.sticker_setting)).setListener(new ToolbarListener() {

        @Override
        public void onLeftIconClickListener(View view) {
            finish();
        }
    }).setContext(getContext());
    linearLayout.addView(helperToolbar.getView());
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    viewModel.getStickersLiveData().observe(getViewLifecycleOwner(), structIGStickerGroups -> adapter.updateAdapter(structIGStickerGroups));
    adapter.setListener(new RemoveStickerAdapter.RemoveStickerDialogListener() {

        @Override
        public void onStickerClick(StructIGStickerGroup stickerGroup) {
            openFragmentAddStickerToFavorite(stickerGroup);
        }

        @Override
        public void onRemoveStickerClick(StructIGStickerGroup stickerGroup, int pos, RemoveStickerAdapter.ProgressStatus progressStatus) {
            if (getContext() != null) {
                new MaterialDialog.Builder(getContext()).title(getResources().getString(R.string.remove_sticker)).content(getResources().getString(R.string.remove_sticker_text)).positiveText(getString(R.string.yes)).negativeText(getString(R.string.no)).onPositive((dialog, which) -> {
                    progressStatus.setVisibility(true);
                    viewModel.removeStickerFromMySticker(stickerGroup, (response, error) -> {
                        if (error == null) {
                            adapter.removeItem(pos);
                        } else {
                            progressStatus.setVisibility(false);
                        }
                    });
                    dialog.dismiss();
                }).show();
            }
        }
    });
    viewModel.getRemoveStickerLiveData().observe(getViewLifecycleOwner(), removedItemPosition -> adapter.removeItem(removedItemPosition));
    TextView removeRecentTv = rootView.findViewById(R.id.tv_stickerSetting_clearRecent);
    removeRecentTv.setOnClickListener(v -> onClearRecentStickerClicked());
    ProgressBar progressBar = rootView.findViewById(R.id.pb_stickerSetting_clearRecent);
    viewModel.getClearRecentStickerLiveData().observe(getViewLifecycleOwner(), progressBar::setVisibility);
    TextView clearInternalStorage = rootView.findViewById(R.id.tv_stickerSetting_clearStorage);
    clearInternalStorage.setOnClickListener(v -> viewModel.clearStickerFromInternalStorage());
    TextView storageSize = rootView.findViewById(R.id.tv_stickerSetting_clearStorageSize);
    viewModel.getStickerFileSizeLiveData().observe(getViewLifecycleOwner(), storageSize::setText);
    TextView clearFavoriteStickerTv = rootView.findViewById(R.id.tv_stickerSetting_clearFavorite);
    clearFavoriteStickerTv.setOnClickListener(v -> onClearFavoriteStickerClicked());
    ProgressBar clearFavoriteStickerPb = rootView.findViewById(R.id.pb_stickerSetting_clearFavorite);
    TextView clearRecentEmojiTv = rootView.findViewById(R.id.tv_stickerSetting_clearEmoji);
    clearRecentEmojiTv.setOnClickListener(v -> onClearRecentEmojiClicked());
    ImageView emptyIv = rootView.findViewById(R.id.iv_stickerSetting_empty);
    TextView emptyTv = rootView.findViewById(R.id.tv_stickerSetting_empty);
    TextView headerTv = rootView.findViewById(R.id.tv_stickerSetting_header);
    viewModel.getEmptyRecentStickerLiveData().observe(getViewLifecycleOwner(), visibility -> {
        emptyIv.setVisibility(visibility);
        emptyTv.setVisibility(visibility);
    });
    viewModel.getRecyclerVisibilityRecentStickerLiveData().observe(getViewLifecycleOwner(), visibility -> {
        recyclerView.setVisibility(visibility);
        headerTv.setVisibility(visibility);
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) HelperToolbar(net.iGap.helper.HelperToolbar) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) LinearLayout(android.widget.LinearLayout)

Example 2 with StructIGStickerGroup

use of net.iGap.fragments.emoji.struct.StructIGStickerGroup in project iGap-Android by KianIranian-STDG.

the class StickerRepository method removeStickerGroupFromMyStickers.

public Single<StructIGStickerGroup> removeStickerGroupFromMyStickers(StructIGStickerGroup stickerGroup) {
    return removeStickerGroupFromMyStickersApiService(stickerGroup.getGroupId()).doOnComplete(() -> DbManager.getInstance().doRealmTask(realm -> {
        RealmStickerGroup realmStickerGroup = realm.where(RealmStickerGroup.class).equalTo("id", stickerGroup.getGroupId()).findFirst();
        if (realmStickerGroup != null) {
            try {
                DbManager.getInstance().doRealmTransaction(asyncRealm -> realmStickerGroup.removeFromRealm());
                stickerGroup.setInUserList(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    })).andThen((SingleSource<StructIGStickerGroup>) observer -> observer.onSuccess(stickerGroup));
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup)

Example 3 with StructIGStickerGroup

use of net.iGap.fragments.emoji.struct.StructIGStickerGroup in project iGap-Android by KianIranian-STDG.

the class StickerRepository method getCategoryStickerGroups.

public Single<List<StructIGStickerGroup>> getCategoryStickerGroups(String categoryId, int skip, int limit, String type) {
    return stickerApi.getCategoryStickers(categoryId, skip, limit, type).subscribeOn(Schedulers.newThread()).map(dataModel -> {
        List<StructIGStickerGroup> groups = new ArrayList<>();
        for (int i = 0; i < dataModel.getData().size(); i++) {
            StructIGStickerGroup stickerGroup = new StructIGStickerGroup(dataModel.getData().get(i));
            groups.add(stickerGroup);
        }
        return groups;
    });
}
Also used : ArrayList(java.util.ArrayList) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup)

Example 4 with StructIGStickerGroup

use of net.iGap.fragments.emoji.struct.StructIGStickerGroup in project iGap-Android by KianIranian-STDG.

the class StickerRepository method getUserStickersGroup.

public void getUserStickersGroup() {
    CompositeDisposable compositeDisposable = new CompositeDisposable();
    stickerApi.getUserStickersGroup().subscribeOn(Schedulers.newThread()).map(dataModel -> {
        List<StructIGStickerGroup> groups = new ArrayList<>();
        for (int i = 0; i < dataModel.getData().size(); i++) {
            StructIGStickerGroup stickerGroup = new StructIGStickerGroup(dataModel.getData().get(i));
            groups.add(stickerGroup);
        }
        return groups;
    }).subscribe(new IGSingleObserver<List<StructIGStickerGroup>>(compositeDisposable) {

        @Override
        public void onSuccess(List<StructIGStickerGroup> structIGStickerGroups) {
            updateStickers(structIGStickerGroups);
            if (!compositeDisposable.isDisposed())
                compositeDisposable.dispose();
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
            if (!compositeDisposable.isDisposed())
                compositeDisposable.dispose();
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) ArrayList(java.util.ArrayList) List(java.util.List) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 5 with StructIGStickerGroup

use of net.iGap.fragments.emoji.struct.StructIGStickerGroup in project iGap-Android by KianIranian-STDG.

the class StickerRepository method getStickerGroupWithRecentTabForEmojiView.

public Flowable<List<StructIGStickerGroup>> getStickerGroupWithRecentTabForEmojiView() {
    return DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmStickerGroup.class).findAllAsync().asFlowable().filter(RealmResults::isLoaded).map(realmStickers -> {
            List<StructIGStickerGroup> structIGStickerGroups = new ArrayList<>();
            for (int i = 0; i < realmStickers.size(); i++) {
                StructIGStickerGroup stickerGroup = new StructIGStickerGroup(realmStickers.get(i));
                structIGStickerGroups.add(stickerGroup);
            }
            return structIGStickerGroups;
        }).map(structIGStickerGroups -> {
            StructIGStickerGroup stickerGroup = new StructIGStickerGroup(StructIGStickerGroup.RECENT_GROUP);
            stickerGroup.setName(G.context.getResources().getString(R.string.recently));
            RealmResults<RealmStickerItem> realmStickersDetails = realm.where(RealmStickerItem.class).limit(RECENT_STICKER_LIMIT).notEqualTo("recentTime", 0).sort("recentTime", Sort.DESCENDING).findAll();
            List<StructIGSticker> stickers = new ArrayList<>();
            for (int i = 0; i < realmStickersDetails.size(); i++) {
                RealmStickerItem stickerItem = realmStickersDetails.get(i);
                if (stickerItem != null) {
                    stickers.add(new StructIGSticker(stickerItem));
                }
            }
            stickerGroup.setStickers(stickers);
            if (stickers.size() > 0) {
                structIGStickerGroups.add(0, stickerGroup);
            }
            return structIGStickerGroups;
        }).map(structIGStickerGroups -> {
            StructIGStickerGroup favoriteStickerGroup = new StructIGStickerGroup(StructIGStickerGroup.FAVORITE_GROUP);
            favoriteStickerGroup.setName(G.context.getResources().getString(R.string.beeptunesÙ€favorite_song));
            RealmResults<RealmStickerItem> stickerItems = realm.where(RealmStickerItem.class).limit(FAVORITE_STICKER_LIMIT).equalTo("isFavorite", true).sort("recentTime", Sort.DESCENDING).findAll();
            if (stickerItems != null) {
                List<StructIGSticker> stickers = new ArrayList<>();
                for (int i = 0; i < stickerItems.size(); i++) {
                    RealmStickerItem stickerItem = stickerItems.get(i);
                    if (stickerItem != null) {
                        stickers.add(new StructIGSticker(stickerItem));
                    }
                }
                favoriteStickerGroup.setStickers(stickers);
            // boolean hasRecent = structIGStickerGroups.get(0).getGroupId().equals(StructIGStickerGroup.RECENT_GROUP);
            // if (stickers.size() > 0) {
            // structIGStickerGroups.add(hasRecent ? 1 : 0, favoriteStickerGroup);
            // }
            }
            return structIGStickerGroups;
        });
    });
}
Also used : JsonObject(com.google.gson.JsonObject) SingleSource(io.reactivex.SingleSource) StickerCategoryGroupDataModel(net.iGap.fragments.emoji.apiModels.StickerCategoryGroupDataModel) FileLog(net.iGap.helper.FileLog) Completable(io.reactivex.Completable) AESCrypt(net.iGap.module.AESCrypt) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) StructIGStickerCategory(net.iGap.fragments.emoji.struct.StructIGStickerCategory) RealmStickerItem(net.iGap.realm.RealmStickerItem) G(net.iGap.G) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SliderDataModel(net.iGap.fragments.emoji.apiModels.SliderDataModel) Flowable(io.reactivex.Flowable) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) RsaDataModel(net.iGap.fragments.emoji.apiModels.RsaDataModel) IGSingleObserver(net.iGap.observers.rx.IGSingleObserver) CardStatusDataModel(net.iGap.fragments.emoji.apiModels.CardStatusDataModel) HelperNumerical(net.iGap.helper.HelperNumerical) Ids(net.iGap.fragments.emoji.apiModels.Ids) CompletableObserver(io.reactivex.CompletableObserver) RealmResults(io.realm.RealmResults) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) StickerApi(net.iGap.api.StickerApi) UserGiftStickersDataModel(net.iGap.fragments.emoji.apiModels.UserGiftStickersDataModel) File(java.io.File) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) RetrofitFactory(net.iGap.api.apiService.RetrofitFactory) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Sort(io.realm.Sort) Base64(android.util.Base64) CardDetailDataModel(net.iGap.fragments.emoji.apiModels.CardDetailDataModel) IssueDataModel(net.iGap.fragments.emoji.apiModels.IssueDataModel) R(net.iGap.R) RealmStickerGroup(net.iGap.realm.RealmStickerGroup) ResponseCallback(net.iGap.observers.interfaces.ResponseCallback) NotNull(org.jetbrains.annotations.NotNull) DbManager(net.iGap.module.accountManager.DbManager) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) RealmResults(io.realm.RealmResults) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Aggregations

StructIGStickerGroup (net.iGap.fragments.emoji.struct.StructIGStickerGroup)13 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)5 R (net.iGap.R)5 StructIGStickerCategory (net.iGap.fragments.emoji.struct.StructIGStickerCategory)5 RealmStickerGroup (net.iGap.realm.RealmStickerGroup)5 Base64 (android.util.Base64)4 Gson (com.google.gson.Gson)4 JsonObject (com.google.gson.JsonObject)4 Completable (io.reactivex.Completable)4 CompletableObserver (io.reactivex.CompletableObserver)4 Flowable (io.reactivex.Flowable)4 Single (io.reactivex.Single)4 SingleSource (io.reactivex.SingleSource)4 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)4 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)4 Disposable (io.reactivex.disposables.Disposable)4 Schedulers (io.reactivex.schedulers.Schedulers)4 RealmResults (io.realm.RealmResults)4 Sort (io.realm.Sort)4