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);
});
}
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));
}
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;
});
}
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();
}
});
}
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;
});
});
}
Aggregations