use of net.iGap.realm.RealmUserInfo in project iGap-Android by KianIranian-STDG.
the class LoginActions method getUserInfo.
private static void getUserInfo() {
final Long userId;
userId = DbManager.getInstance().doRealmTask(realm -> {
try {
RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
if (realmUserInfo == null) {
throw new Exception("Empty Exception");
}
return realmUserInfo.getUserId();
} catch (Exception e) {
e.printStackTrace();
Log.wtf(LoginActions.class.getName(), "catch");
G.logoutAccount.postValue(true);
return null;
}
});
if (userId == null)
return;
new RequestUserInfo().userInfo(userId);
}
use of net.iGap.realm.RealmUserInfo in project iGap-Android by KianIranian-STDG.
the class Type0ViewHolder method bindView.
@Override
public void bindView(DiscoveryItem item) {
itemView.setOnClickListener(view -> new HelperFragment(G.currentActivity.getSupportFragmentManager(), new FragmentUserScore()).setReplace(false).load());
DbManager.getInstance().doRealmTask(realm -> {
RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst();
if (userInfo != null)
tvScore.setText(HelperCalander.isPersianUnicode ? HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(userInfo.getIvandScore())) : String.valueOf(userInfo.getIvandScore()));
});
Animation animation = AnimationUtils.loadAnimation(itemView.getContext(), R.anim.shake_mode);
animation.reset();
tvContent.clearAnimation();
tvContent.startAnimation(animation);
}
use of net.iGap.realm.RealmUserInfo in project iGap-Android by KianIranian-STDG.
the class TokenContainer method getToken.
public String getToken() {
String result = "Bearer ";
String dbToken = DbManager.getInstance().doRealmTask(realm -> {
RealmUserInfo realmUserInfo = realm.where(RealmUserInfo.class).findFirst();
if (realmUserInfo != null) {
return realmUserInfo.getAccessToken();
}
return null;
});
if (dbToken != null) {
token = dbToken;
}
result += token;
if (BuildConfig.DEBUG)
Log.i(getClass().getSimpleName(), "ApiToken: " + token);
return result;
}
use of net.iGap.realm.RealmUserInfo in project iGap-Android by KianIranian-STDG.
the class HelperToolbar method onScannerClickListener.
private void onScannerClickListener() {
DbManager.getInstance().doRealmTask(realm -> {
String phoneNumber = "";
RealmUserInfo userInfo = realm.where(RealmUserInfo.class).findFirst();
try {
if (userInfo != null) {
phoneNumber = userInfo.getUserInfo().getPhoneNumber().substring(2);
} else {
phoneNumber = AccountManager.getInstance().getCurrentUser().getPhoneNumber().substring(2);
}
} catch (Exception e) {
// maybe exception was for realm substring
try {
phoneNumber = AccountManager.getInstance().getCurrentUser().getPhoneNumber().substring(2);
} catch (Exception ex) {
// nothing
}
}
});
}
use of net.iGap.realm.RealmUserInfo in project iGap-Android by KianIranian-STDG.
the class BotInit method onClick.
@Override
public void onClick(View v, ButtonEntity buttonEntity) {
DbManager.getInstance().doRealmTask(realm -> {
try {
if (v.getId() == ButtonActionType.USERNAME_LINK) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(1), HelperUrl.ChatEntry.chat, 0, 0);
} else if (v.getId() == ButtonActionType.BOT_ACTION) {
try {
Long identity = System.currentTimeMillis();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(roomId, identity, ((ArrayList<String>) v.getTag()).get(1), ((ArrayList<String>) v.getTag()).get(2), 3, realm, ProtoGlobal.RoomMessageType.TEXT);
MessageObject botMessage = MessageObject.create(realmRoomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(ProtoGlobal.Room.Type.CHAT, roomId, botMessage);
if (G.onBotClick != null) {
G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
}
}
});
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.JOIN_LINK) {
HelperUrl.checkAndJoinToRoom(G.currentActivity, ((ArrayList<String>) v.getTag()).get(0).substring(14));
} else if (v.getId() == ButtonActionType.WEB_LINK) {
HelperUrl.openBrowser(((ArrayList<String>) v.getTag()).get(0));
} else if (v.getId() == ButtonActionType.WEBVIEW_LINK) {
G.onBotClick.onBotCommandText(((ArrayList<String>) v.getTag()).get(0), ButtonActionType.WEBVIEW_LINK);
} else if (v.getId() == ButtonActionType.REQUEST_PHONE) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_phone_number).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Long identity = System.currentTimeMillis();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmUserInfo realmUserInfo = RealmUserInfo.getRealmUserInfo(realm);
RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(roomId, identity, realmUserInfo.getUserInfo().getPhoneNumber(), realmUserInfo.getUserInfo().getPhoneNumber(), 0, realm, ProtoGlobal.RoomMessageType.TEXT);
MessageObject botMessage = MessageObject.create(realmRoomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(ProtoGlobal.Room.Type.CHAT, roomId, botMessage);
if (G.onBotClick != null) {
G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
}
}
});
}
}).show();
} catch (Exception e) {
}
} else if (v.getId() == ButtonActionType.REQUEST_LOCATION) {
try {
new MaterialDialog.Builder(G.currentActivity).title(R.string.access_location).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Boolean response = false;
if (G.locationListener != null) {
isLocationFromBot = true;
G.locationListener.requestLocation();
}
/* G.locationListenerResponse = new LocationListenerResponse() {
@Override
public void setLocationResponse(Double latitude, Double longitude) {
Long identity = System.currentTimeMillis();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmRoomMessage realmRoomMessage = RealmRoomMessage.makeAdditionalData(roomId, identity, latitude + "," + longitude, ((ArrayList<String>) v.getTag()).get(2).toString(), 3, realm, ProtoGlobal.RoomMessageType.TEXT);
G.chatSendMessageUtil.build(ProtoGlobal.Room.Type.CHAT, roomId, realmRoomMessage).sendMessage(identity + "");
if (G.onBotClick != null) {
G.onBotClick.onBotCommandText(realmRoomMessage, ButtonActionType.BOT_ACTION);
}
}
});
}
};*/
}
}).show();
} catch (Exception e) {
}
}
} catch (Exception e) {
Toast.makeText(G.context, "دستور با خطا مواجه شد", Toast.LENGTH_LONG).show();
}
});
}
Aggregations