mirror of
https://github.com/openMF/mobile-wallet.git
synced 2026-02-06 11:56:48 +00:00
refactor #1476: migrated data package from java to kotlin
This commit is contained in:
parent
eed2c7571a
commit
2c2bc35d56
@ -13,47 +13,37 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mifos.mobilewallet.mifospay.data.firebase.api.services
|
||||
|
||||
package org.mifos.mobilewallet.mifospay.data.firebase.api.services;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mifos.mobilewallet.mifospay.R;
|
||||
import org.mifos.mobilewallet.mifospay.notification.ui.NotificationActivity;
|
||||
import org.mifos.mobilewallet.mifospay.utils.NotificationUtils;
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.google.firebase.messaging.FirebaseMessagingService
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import org.mifos.mobilewallet.mifospay.R
|
||||
import org.mifos.mobilewallet.mifospay.notification.ui.NotificationActivity
|
||||
import org.mifos.mobilewallet.mifospay.utils.NotificationUtils
|
||||
|
||||
/**
|
||||
* Created by ankur on 20/June/2018
|
||||
*/
|
||||
|
||||
public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
|
||||
private static final String TAG = "MifosPayFCM";
|
||||
|
||||
|
||||
class MifosPayMessagingService : FirebaseMessagingService() {
|
||||
/**
|
||||
* Called if InstanceID token is updated. This may occur if the security of
|
||||
* the previous token had been compromised. Note that this is called when the InstanceID token
|
||||
* is initially generated so this is where you would retrieve the token.
|
||||
*/
|
||||
@Override
|
||||
public void onNewToken(String token) {
|
||||
super.onNewToken(token);
|
||||
Log.d(TAG, "Refreshed token: " + token);
|
||||
override fun onNewToken(token: String) {
|
||||
super.onNewToken(token)
|
||||
Log.d(TAG, "Refreshed token: $token")
|
||||
// If you want to send messages to this application instance or
|
||||
// manage this apps subscriptions on the server side, send the
|
||||
// Instance ID token to your app server.
|
||||
@ -65,8 +55,7 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
|
||||
*/
|
||||
// [START receive_message]
|
||||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
||||
// [START_EXCLUDE]
|
||||
// There are two types of messages data messages and notification messages. Data messages
|
||||
// are handled
|
||||
@ -84,18 +73,17 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
// [END_EXCLUDE]
|
||||
|
||||
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
|
||||
Log.d(TAG, "From: " + remoteMessage.getFrom());
|
||||
Log.d(TAG, "From: " + remoteMessage.from)
|
||||
|
||||
// Check if message contains a data payload.
|
||||
// We will use data messages and hence our messages will be handled here
|
||||
if (remoteMessage.getData().size() > 0) {
|
||||
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
|
||||
|
||||
if (remoteMessage.data.size > 0) {
|
||||
Log.d(TAG, "Message data payload: " + remoteMessage.data)
|
||||
try {
|
||||
JSONObject json = new JSONObject(remoteMessage.getData().toString());
|
||||
handleDataMessage(json);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Exception: " + e.getMessage());
|
||||
val json = JSONObject(remoteMessage.data.toString())
|
||||
handleDataMessage(json)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception: " + e.message)
|
||||
}
|
||||
|
||||
// if (/* Check if data needs to be processed by long running job */ true) {
|
||||
@ -119,18 +107,16 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
// Also if you intend on generating your own notifications as a result of a received FCM
|
||||
// message, here is where that should be initiated. See sendNotification method below.
|
||||
}
|
||||
|
||||
// [END receive_message]
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeletedMessages() {
|
||||
super.onDeletedMessages();
|
||||
override fun onDeletedMessages() {
|
||||
super.onDeletedMessages()
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a job using FirebaseJobDispatcher.
|
||||
*/
|
||||
private void scheduleJob() {
|
||||
private fun scheduleJob() {
|
||||
// [START dispatch_job]
|
||||
// FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
|
||||
// Job myJob = dispatcher.newJobBuilder()
|
||||
@ -144,9 +130,8 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
/**
|
||||
* Handle time allotted to BroadcastReceivers.
|
||||
*/
|
||||
private void handleNow() {
|
||||
|
||||
Log.d(TAG, "Short lived task is done.");
|
||||
private fun handleNow() {
|
||||
Log.d(TAG, "Short lived task is done.")
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,74 +139,67 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
*
|
||||
* @param messageBody FCM message body received.
|
||||
*/
|
||||
private void sendNotification(String title, String messageBody) {
|
||||
Intent intent = new Intent(this, NotificationActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent;
|
||||
pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */,
|
||||
intent,
|
||||
PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
String channelId = getString(R.string.app_name);
|
||||
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(this, channelId)
|
||||
.setSmallIcon(R.drawable.ic_bank)
|
||||
.setContentTitle(title)
|
||||
.setContentText(messageBody)
|
||||
.setAutoCancel(true)
|
||||
.setSound(defaultSoundUri)
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
private fun sendNotification(title: String, messageBody: String) {
|
||||
val intent = Intent(this, NotificationActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
val pendingIntent: PendingIntent
|
||||
pendingIntent = PendingIntent.getActivity(
|
||||
this, 0 /* Request code */,
|
||||
intent,
|
||||
PendingIntent.FLAG_ONE_SHOT
|
||||
)
|
||||
val channelId = getString(R.string.app_name)
|
||||
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
val notificationBuilder = NotificationCompat.Builder(this, channelId)
|
||||
.setSmallIcon(R.drawable.ic_bank)
|
||||
.setContentTitle(title)
|
||||
.setContentText(messageBody)
|
||||
.setAutoCancel(true)
|
||||
.setSound(defaultSoundUri)
|
||||
.setContentIntent(pendingIntent)
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
// Since android Oreo notification channel is needed.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(channelId,
|
||||
"Channel human readable title",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
val channel = NotificationChannel(
|
||||
channelId,
|
||||
"Channel human readable title",
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
|
||||
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles notification messages.
|
||||
*/
|
||||
private void handleNotification(String title, String message) {
|
||||
|
||||
}
|
||||
private fun handleNotification(title: String, message: String) {}
|
||||
|
||||
/**
|
||||
* Handles data messages.
|
||||
*/
|
||||
private void handleDataMessage(JSONObject json) {
|
||||
Log.e(TAG, "push json: " + json.toString());
|
||||
|
||||
private fun handleDataMessage(json: JSONObject) {
|
||||
Log.e(TAG, "push json: $json")
|
||||
try {
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
|
||||
String title = data.getString("title");
|
||||
String message = data.getString("message");
|
||||
String imageUrl = data.getString("image");
|
||||
String type = data.getString("type");
|
||||
String timestamp = data.getString("timestamp");
|
||||
JSONObject payload = data.getJSONObject("payload");
|
||||
|
||||
Log.e(TAG, "title: " + title);
|
||||
Log.e(TAG, "message: " + message);
|
||||
Log.e(TAG, "type: " + type);
|
||||
val data = json.getJSONObject("data")
|
||||
val title = data.getString("title")
|
||||
val message = data.getString("message")
|
||||
val imageUrl = data.getString("image")
|
||||
val type = data.getString("type")
|
||||
val timestamp = data.getString("timestamp")
|
||||
val payload = data.getJSONObject("payload")
|
||||
Log.e(TAG, "title: $title")
|
||||
Log.e(TAG, "message: $message")
|
||||
Log.e(TAG, "type: $type")
|
||||
// payload can be used when one needs to show specific notification with some data
|
||||
// and process it
|
||||
if (payload != null) {
|
||||
Log.e(TAG, "payload: " + payload.toString());
|
||||
Log.e(TAG, "payload: $payload")
|
||||
}
|
||||
Log.e(TAG, "imageUrl: " + imageUrl);
|
||||
Log.e(TAG, "timestamp: " + timestamp);
|
||||
|
||||
sendNotification(title, message);
|
||||
Log.e(TAG, "imageUrl: $imageUrl")
|
||||
Log.e(TAG, "timestamp: $timestamp")
|
||||
sendNotification(title, message)
|
||||
|
||||
// Below code can be used when you want to show notification with Image.
|
||||
|
||||
@ -237,31 +215,38 @@ public class MifosPayMessagingService extends FirebaseMessagingService {
|
||||
// showNotificationMessageWithBigImage(getApplicationContext(), title, message,
|
||||
// timestamp, resultIntent, imageUrl);
|
||||
// }
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "Json Exception: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Exception: " + e.getMessage());
|
||||
} catch (e: JSONException) {
|
||||
Log.e(TAG, "Json Exception: " + e.message)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Exception: " + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Showing notification with text only
|
||||
*/
|
||||
private void showNotificationMessage(Context context, String title, String message,
|
||||
String timeStamp, Intent intent) {
|
||||
NotificationUtils notificationUtils = new NotificationUtils(context);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
|
||||
private fun showNotificationMessage(
|
||||
context: Context, title: String, message: String,
|
||||
timeStamp: String, intent: Intent
|
||||
) {
|
||||
val notificationUtils = NotificationUtils(context)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
notificationUtils.showNotificationMessage(title, message, timeStamp, intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Showing notification with text and image
|
||||
*/
|
||||
private void showNotificationMessageWithBigImage(Context context, String title, String message,
|
||||
String timeStamp, Intent intent, String imageUrl) {
|
||||
NotificationUtils notificationUtils = new NotificationUtils(context);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl);
|
||||
private fun showNotificationMessageWithBigImage(
|
||||
context: Context, title: String, message: String,
|
||||
timeStamp: String, intent: Intent, imageUrl: String
|
||||
) {
|
||||
val notificationUtils = NotificationUtils(context)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MifosPayFCM"
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package org.mifos.mobilewallet.mifospay.data.local;
|
||||
|
||||
import org.mifos.mobilewallet.core.domain.model.client.Client;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Created by naman on 17/6/17.
|
||||
*/
|
||||
|
||||
@Singleton
|
||||
public class LocalRepository {
|
||||
|
||||
private final PreferencesHelper preferencesHelper;
|
||||
|
||||
@Inject
|
||||
public LocalRepository(PreferencesHelper preferencesHelper) {
|
||||
this.preferencesHelper = preferencesHelper;
|
||||
}
|
||||
|
||||
public Client getClientDetails() {
|
||||
Client details = new Client();
|
||||
details.setName(preferencesHelper.getFullName());
|
||||
details.setClientId(preferencesHelper.getClientId());
|
||||
details.setExternalId(preferencesHelper.getClientVpa());
|
||||
return details;
|
||||
}
|
||||
|
||||
public void saveClientData(Client client) {
|
||||
preferencesHelper.saveFullName(client.getName());
|
||||
preferencesHelper.setClientId(client.getClientId());
|
||||
preferencesHelper.setClientVpa(client.getExternalId());
|
||||
}
|
||||
|
||||
public PreferencesHelper getPreferencesHelper() {
|
||||
return preferencesHelper;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package org.mifos.mobilewallet.mifospay.data.local
|
||||
|
||||
import org.mifos.mobilewallet.core.domain.model.client.Client
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by naman on 17/6/17.
|
||||
*/
|
||||
@Singleton
|
||||
class LocalRepository @Inject constructor(val preferencesHelper: PreferencesHelper) {
|
||||
|
||||
val clientDetails: Client
|
||||
get() {
|
||||
val details = Client()
|
||||
details.name = preferencesHelper.fullName
|
||||
details.clientId = preferencesHelper.clientId
|
||||
details.externalId = preferencesHelper.clientVpa
|
||||
return details
|
||||
}
|
||||
|
||||
fun saveClientData(client: Client) {
|
||||
preferencesHelper.saveFullName(client.name)
|
||||
preferencesHelper.clientId = client.clientId
|
||||
preferencesHelper.clientVpa = client.externalId
|
||||
}
|
||||
}
|
||||
@ -1,150 +0,0 @@
|
||||
package org.mifos.mobilewallet.mifospay.data.local;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Created by naman on 17/6/17.
|
||||
*/
|
||||
|
||||
@Singleton
|
||||
public class PreferencesHelper {
|
||||
|
||||
private static final String TOKEN = "preferences_token";
|
||||
private static final String NAME = "preferences_name";
|
||||
private static final String USERNAME = "preferences_user_name";
|
||||
private static final String EMAIL = "preferences_email";
|
||||
private static final String CLIENT_ID = "preferences_client";
|
||||
private static final String USER_ID = "preferences_user_id";
|
||||
private static final String CLIENT_VPA = "preferences_client_vpa";
|
||||
private static final String MOBILE_NO = "preferences_mobile_no";
|
||||
private static final String FIREBASE_REG_ID = "preferences_firebase_reg_id";
|
||||
private static final String ACCOUNT_ID = "preferences_account_id";
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
@Inject
|
||||
public PreferencesHelper(@ApplicationContext Context context) {
|
||||
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
sharedPreferences.edit().clear().apply();
|
||||
}
|
||||
|
||||
|
||||
public int getInt(String preferenceKey, int preferenceDefaultValue) {
|
||||
return sharedPreferences.getInt(preferenceKey, preferenceDefaultValue);
|
||||
}
|
||||
|
||||
public void putInt(String preferenceKey, int preferenceValue) {
|
||||
sharedPreferences.edit().putInt(preferenceKey, preferenceValue).apply();
|
||||
}
|
||||
|
||||
public long getLong(String preferenceKey, long preferenceDefaultValue) {
|
||||
return sharedPreferences.getLong(preferenceKey, preferenceDefaultValue);
|
||||
}
|
||||
|
||||
public void putLong(String preferenceKey, long preferenceValue) {
|
||||
sharedPreferences.edit().putLong(preferenceKey, preferenceValue).apply();
|
||||
}
|
||||
|
||||
public String getString(String preferenceKey, String preferenceDefaultValue) {
|
||||
return sharedPreferences.getString(preferenceKey, preferenceDefaultValue);
|
||||
}
|
||||
|
||||
public void putString(String preferenceKey, String preferenceValue) {
|
||||
sharedPreferences.edit().putString(preferenceKey, preferenceValue).apply();
|
||||
}
|
||||
|
||||
public void saveToken(String token) {
|
||||
putString(TOKEN, token);
|
||||
}
|
||||
|
||||
public void clearToken() {
|
||||
putString(TOKEN, "");
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return getString(TOKEN, "");
|
||||
}
|
||||
|
||||
public void saveFullName(String name) {
|
||||
putString(NAME, name);
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return getString(NAME, "");
|
||||
}
|
||||
|
||||
public void saveUsername(String name) {
|
||||
putString(USERNAME, name);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return getString(USERNAME, "");
|
||||
}
|
||||
|
||||
public void saveEmail(String email) {
|
||||
putString(EMAIL, email);
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return getString(EMAIL, "");
|
||||
}
|
||||
|
||||
public void saveMobile(String mobile) {
|
||||
putString(MOBILE_NO, mobile);
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return getString(MOBILE_NO, "");
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return getLong(USER_ID, -1);
|
||||
}
|
||||
|
||||
public void setUserId(long id) {
|
||||
putLong(USER_ID, id);
|
||||
}
|
||||
|
||||
public long getClientId() {
|
||||
return getLong(CLIENT_ID, 1);
|
||||
}
|
||||
|
||||
public void setClientId(long clientId) {
|
||||
putLong(CLIENT_ID, clientId);
|
||||
}
|
||||
|
||||
public String getClientVpa() {
|
||||
return getString(CLIENT_VPA, "");
|
||||
}
|
||||
|
||||
public void setClientVpa(String vpa) {
|
||||
putString(CLIENT_VPA, vpa);
|
||||
}
|
||||
|
||||
public void setAccountId(long accountId) {
|
||||
putLong(ACCOUNT_ID, accountId);
|
||||
}
|
||||
|
||||
public Long getAccountId() {
|
||||
return getLong(ACCOUNT_ID, 0);
|
||||
}
|
||||
|
||||
public String getFirebaseRegId() {
|
||||
return getString(FIREBASE_REG_ID, "");
|
||||
}
|
||||
|
||||
public void setFirebaseRegId(String firebaseRegId) {
|
||||
putString(FIREBASE_REG_ID, firebaseRegId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,125 @@
|
||||
package org.mifos.mobilewallet.mifospay.data.local
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.preference.PreferenceManager
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Created by naman on 17/6/17.
|
||||
*/
|
||||
@Singleton
|
||||
class PreferencesHelper @Inject constructor(@ApplicationContext context: Context?) {
|
||||
private val sharedPreferences: SharedPreferences
|
||||
|
||||
init {
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
sharedPreferences.edit().clear().apply()
|
||||
}
|
||||
|
||||
fun getInt(preferenceKey: String?, preferenceDefaultValue: Int): Int {
|
||||
return sharedPreferences.getInt(preferenceKey, preferenceDefaultValue)
|
||||
}
|
||||
|
||||
fun putInt(preferenceKey: String?, preferenceValue: Int) {
|
||||
sharedPreferences.edit().putInt(preferenceKey, preferenceValue).apply()
|
||||
}
|
||||
|
||||
fun getLong(preferenceKey: String?, preferenceDefaultValue: Long): Long {
|
||||
return sharedPreferences.getLong(preferenceKey, preferenceDefaultValue)
|
||||
}
|
||||
|
||||
fun putLong(preferenceKey: String?, preferenceValue: Long) {
|
||||
sharedPreferences.edit().putLong(preferenceKey, preferenceValue).apply()
|
||||
}
|
||||
|
||||
fun getString(preferenceKey: String?, preferenceDefaultValue: String?): String? {
|
||||
return sharedPreferences.getString(preferenceKey, preferenceDefaultValue)
|
||||
}
|
||||
|
||||
fun putString(preferenceKey: String?, preferenceValue: String?) {
|
||||
sharedPreferences.edit().putString(preferenceKey, preferenceValue).apply()
|
||||
}
|
||||
|
||||
fun saveToken(token: String?) {
|
||||
putString(TOKEN, token)
|
||||
}
|
||||
|
||||
fun clearToken() {
|
||||
putString(TOKEN, "")
|
||||
}
|
||||
|
||||
val token: String?
|
||||
get() = getString(TOKEN, "")
|
||||
|
||||
fun saveFullName(name: String?) {
|
||||
putString(NAME, name)
|
||||
}
|
||||
|
||||
val fullName: String?
|
||||
get() = getString(NAME, "")
|
||||
|
||||
fun saveUsername(name: String?) {
|
||||
putString(USERNAME, name)
|
||||
}
|
||||
|
||||
val username: String?
|
||||
get() = getString(USERNAME, "")
|
||||
|
||||
fun saveEmail(email: String?) {
|
||||
putString(EMAIL, email)
|
||||
}
|
||||
|
||||
val email: String?
|
||||
get() = getString(EMAIL, "")
|
||||
|
||||
fun saveMobile(mobile: String?) {
|
||||
putString(MOBILE_NO, mobile)
|
||||
}
|
||||
|
||||
val mobile: String?
|
||||
get() = getString(MOBILE_NO, "")
|
||||
var userId: Long
|
||||
get() = getLong(USER_ID, -1)
|
||||
set(id) {
|
||||
putLong(USER_ID, id)
|
||||
}
|
||||
var clientId: Long
|
||||
get() = getLong(CLIENT_ID, 1)
|
||||
set(clientId) {
|
||||
putLong(CLIENT_ID, clientId)
|
||||
}
|
||||
var clientVpa: String?
|
||||
get() = getString(CLIENT_VPA, "")
|
||||
set(vpa) {
|
||||
putString(CLIENT_VPA, vpa)
|
||||
}
|
||||
var accountId: Long
|
||||
get() = getLong(ACCOUNT_ID, 0)
|
||||
set(accountId) {
|
||||
putLong(ACCOUNT_ID, accountId)
|
||||
}
|
||||
var firebaseRegId: String?
|
||||
get() = getString(FIREBASE_REG_ID, "")
|
||||
set(firebaseRegId) {
|
||||
putString(FIREBASE_REG_ID, firebaseRegId)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TOKEN = "preferences_token"
|
||||
private const val NAME = "preferences_name"
|
||||
private const val USERNAME = "preferences_user_name"
|
||||
private const val EMAIL = "preferences_email"
|
||||
private const val CLIENT_ID = "preferences_client"
|
||||
private const val USER_ID = "preferences_user_id"
|
||||
private const val CLIENT_VPA = "preferences_client_vpa"
|
||||
private const val MOBILE_NO = "preferences_mobile_no"
|
||||
private const val FIREBASE_REG_ID = "preferences_firebase_reg_id"
|
||||
private const val ACCOUNT_ID = "preferences_account_id"
|
||||
}
|
||||
}
|
||||
@ -58,25 +58,25 @@ class EditProfilePresenter @Inject constructor(
|
||||
}
|
||||
|
||||
private fun showUsernameIfNotEmpty() {
|
||||
if (!mPreferencesHelper.username.isEmpty()) {
|
||||
if (mPreferencesHelper.username?.isNotEmpty() == true) {
|
||||
mEditProfileView!!.showUsername(mPreferencesHelper.username)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showEmailIfNotEmpty() {
|
||||
if (!mPreferencesHelper.email.isEmpty()) {
|
||||
if (mPreferencesHelper.email?.isNotEmpty() == true) {
|
||||
mEditProfileView!!.showEmail(mPreferencesHelper.email)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showVpaIfNotEmpty() {
|
||||
if (!mPreferencesHelper.clientVpa.isEmpty()) {
|
||||
if (mPreferencesHelper.clientVpa?.isNotEmpty() == true) {
|
||||
mEditProfileView!!.showVpa(mPreferencesHelper.clientVpa)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMobielIfNotEmpty() {
|
||||
if (!mPreferencesHelper.mobile.isEmpty()) {
|
||||
if (mPreferencesHelper.mobile?.isNotEmpty() == true) {
|
||||
mEditProfileView!!.showMobileNumber(mPreferencesHelper.mobile)
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,14 +71,14 @@ class HomeViewModel @Inject constructor(
|
||||
FetchAccount.RequestValues(localRepository.clientDetails.clientId),
|
||||
object : UseCaseCallback<FetchAccount.ResponseValue?> {
|
||||
override fun onSuccess(response: FetchAccount.ResponseValue?) {
|
||||
preferencesHelper.accountId = response?.account?.id
|
||||
preferencesHelper.accountId = response?.account?.id!!
|
||||
|
||||
_homeUIState.update { currentState ->
|
||||
currentState.copy(account = response?.account)
|
||||
currentState.copy(account = response.account)
|
||||
}
|
||||
|
||||
mHomeView?.setAccountBalance(response?.account)
|
||||
response?.account?.id?.let { transactionsHistory?.fetchTransactionsHistory(it) }
|
||||
mHomeView?.setAccountBalance(response.account)
|
||||
response.account?.id?.let { transactionsHistory?.fetchTransactionsHistory(it) }
|
||||
mHomeView?.hideSwipeProgress()
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class MainPresenter @Inject constructor(
|
||||
FetchClientData.RequestValues(localRepository.clientDetails.clientId),
|
||||
object : UseCaseCallback<FetchClientData.ResponseValue?> {
|
||||
override fun onSuccess(response: FetchClientData.ResponseValue?) {
|
||||
localRepository.saveClientData(response?.userDetails)
|
||||
response?.userDetails?.let { localRepository.saveClientData(it) }
|
||||
if (response?.userDetails?.name != "") {
|
||||
// mHomeView?.showClientDetails(response?.userDetails) // TODO: Figure out the purpose of this
|
||||
}
|
||||
|
||||
@ -35,9 +35,9 @@ class ProfilePresenter @Inject constructor(
|
||||
val email = mPreferencesHelper.email
|
||||
val vpa = mPreferencesHelper.clientVpa
|
||||
val mobile = mPreferencesHelper.mobile
|
||||
mProfileView?.showEmail(email.ifEmpty { "-" })
|
||||
mProfileView?.showVpa(vpa.ifEmpty { "-" })
|
||||
mProfileView?.showMobile(mobile.ifEmpty { "-" })
|
||||
mProfileView?.showEmail(email?.ifEmpty { "-" })
|
||||
mProfileView?.showVpa(vpa?.ifEmpty { "-" })
|
||||
mProfileView?.showMobile(mobile?.ifEmpty { "-" })
|
||||
}
|
||||
|
||||
override fun fetchClientImage() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user