New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: notification integration [WIP] #759

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+467 −0
Diff settings

Always

Just for now

@@ -140,6 +140,14 @@
<service android:name=".activity.pathtracking.PathTrackingService" <service android:name=".activity.pathtracking.PathTrackingService"
android:exported="false"/> android:exported="false"/>
<activity
android:name=".online.notification.NotificationDetailActivity"
android:label="@string/title_activity_notification_detail"
android:screenOrientation="portrait"/>
<service
android:name=".online.notification.NotificationFetchService"
android:exported="false"/>
</application> </application>
</manifest> </manifest>
@@ -18,6 +18,7 @@
import com.mifos.api.services.GroupService; import com.mifos.api.services.GroupService;
import com.mifos.api.services.LoanService; import com.mifos.api.services.LoanService;
import com.mifos.api.services.NoteService; import com.mifos.api.services.NoteService;
import com.mifos.api.services.NotificationService;
import com.mifos.api.services.OfficeService; import com.mifos.api.services.OfficeService;
import com.mifos.api.services.RunReportsService; import com.mifos.api.services.RunReportsService;
import com.mifos.api.services.SavingsAccountService; import com.mifos.api.services.SavingsAccountService;
@@ -58,6 +59,7 @@
private static RunReportsService runreportsService; private static RunReportsService runreportsService;
private static NoteService noteService; private static NoteService noteService;
private static CollectionSheetService collectionSheetService; private static CollectionSheetService collectionSheetService;
private static NotificationService notificationService;
public BaseApiManager() { public BaseApiManager() {
createService(); createService();
@@ -81,6 +83,7 @@ public static void init() {
runreportsService = createApi(RunReportsService.class); runreportsService = createApi(RunReportsService.class);
noteService = createApi(NoteService.class); noteService = createApi(NoteService.class);
collectionSheetService = createApi(CollectionSheetService.class); collectionSheetService = createApi(CollectionSheetService.class);
notificationService = createApi(NotificationService.class);
} }
private static <T> T createApi(Class<T> clazz) { private static <T> T createApi(Class<T> clazz) {
@@ -169,4 +172,8 @@ public NoteService getNoteApi() {
public CollectionSheetService getCollectionSheetApi() { public CollectionSheetService getCollectionSheetApi() {
return collectionSheetService; return collectionSheetService;
} }
public NotificationService getNotificationApi() {
return notificationService;
}
} }
@@ -3,6 +3,7 @@
import com.mifos.api.datamanager.DataManagerClient; import com.mifos.api.datamanager.DataManagerClient;
import com.mifos.api.model.CollectionSheetPayload; import com.mifos.api.model.CollectionSheetPayload;
import com.mifos.api.model.Payload; import com.mifos.api.model.Payload;
import com.mifos.objects.NotificationTemplate;
import com.mifos.objects.accounts.loan.LoanApproval; import com.mifos.objects.accounts.loan.LoanApproval;
import com.mifos.objects.accounts.loan.LoanWithAssociations; import com.mifos.objects.accounts.loan.LoanWithAssociations;
import com.mifos.objects.accounts.loan.Loans; import com.mifos.objects.accounts.loan.Loans;
@@ -178,4 +179,8 @@ public DataManager(BaseApiManager baseApiManager,
public Observable<Page<Charges>> getListOfCharges(int clientId) { public Observable<Page<Charges>> getListOfCharges(int clientId) {
return mBaseApiManager.getLoanApi().getListOfCharges(clientId); return mBaseApiManager.getLoanApi().getListOfCharges(clientId);
} }
public Observable<NotificationTemplate> getNotification() {
return mBaseApiManager.getNotificationApi().getNotification();
}
} }
@@ -5,6 +5,11 @@
package com.mifos.api; package com.mifos.api;
import android.content.Context;
import android.content.Intent;
import com.mifos.App;
import com.mifos.mifosxdroid.online.notification.NotificationFetchService;
import com.mifos.utils.PrefManager; import com.mifos.utils.PrefManager;
import java.io.IOException; import java.io.IOException;
@@ -21,13 +26,21 @@
public static final String HEADER_TENANT = "Fineract-Platform-TenantId"; public static final String HEADER_TENANT = "Fineract-Platform-TenantId";
public static final String HEADER_AUTH = "Authorization"; public static final String HEADER_AUTH = "Authorization";
private Context context;
public MifosInterceptor() { public MifosInterceptor() {
} }
@Override @Override
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {
context = App.getContext();
Request chianrequest = chain.request(); Request chianrequest = chain.request();
//String notificationHeader = chain.proceed(chianrequest).header("X-Notification-Refresh");
String notificationHeader = chain.proceed(chianrequest).header("Vary");
if (notificationHeader.equals("Accept-Encoding")) {
//if(notificationHeader.equals("true")) {
context.startService(new Intent(context, NotificationFetchService.class));
}
Builder builder = chianrequest.newBuilder() Builder builder = chianrequest.newBuilder()
.header(HEADER_TENANT, PrefManager.getTenant()); .header(HEADER_TENANT, PrefManager.getTenant());
@@ -31,6 +31,7 @@
public static final String STAFF = "staff"; public static final String STAFF = "staff";
public static final String RUNREPORTS = "runreports"; public static final String RUNREPORTS = "runreports";
public static final String COLLECTIONSHEET = "collectionsheet"; public static final String COLLECTIONSHEET = "collectionsheet";
public static final String NOTIFICATION = "notification";
public static final String SAVINGSACCOUNTS = "savingsaccounts"; public static final String SAVINGSACCOUNTS = "savingsaccounts";
public static final String RECURRING_ACCOUNTS = "recurringdepositaccounts"; public static final String RECURRING_ACCOUNTS = "recurringdepositaccounts";
@@ -0,0 +1,17 @@
package com.mifos.api.services;
import com.mifos.api.model.APIEndPoint;
import com.mifos.objects.NotificationTemplate;
import retrofit2.http.GET;
import rx.Observable;
/**
* Created by mayankjindal on 14/08/17.
*/
public interface NotificationService {
@GET(APIEndPoint.NOTIFICATION)
Observable<NotificationTemplate> getNotification();
}
@@ -0,0 +1,31 @@
package com.mifos.mifosxdroid.online.notification;
import android.os.Bundle;
import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.core.MifosBaseActivity;
import com.mifos.utils.Constants;
public class NotificationDetailActivity extends MifosBaseActivity {
private String subject;
private String object;
private String action;
private String actor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toolbar_container);
showBackButton();
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
subject = bundle.getString(Constants.NOTIFICATION_SUBJECT);
object = bundle.getString(Constants.NOTIFICATION_OBJECT);
action = bundle.getString(Constants.NOTIFICATION_ACTION);
actor = bundle.getString(Constants.NOTIFICATION_ACTOR);
}
}
}
@@ -0,0 +1,54 @@
package com.mifos.mifosxdroid.online.notification;
import android.app.IntentService;
import android.content.Intent;
import rx.Subscription;
/**
* Created by mayankjindal on 14/08/17.
*/
public class NotificationFetchService extends IntentService {
//private final DataManager mDataManager;
private Subscription mSubscription;
public NotificationFetchService() {
super("NotificationFetchService");
}
// @Inject
// public NotificationFetchService(String name,
// DataManager dataManager) {
// super(name);
// mDataManager = dataManager;

This comment has been minimized.

@mayank-kgp

mayank-kgp Aug 15, 2017

Contributor

@therajanmaurya How can I initialize DataManager object here?
For using IntentService, I have to use the constructor with no argument. Otherwise, I get an error "intentservice has no zero argument constructor". But I want to use DataManager object for fetching notification.
And you can check my whole approach too.

@mayank-kgp

mayank-kgp Aug 15, 2017

Contributor

@therajanmaurya How can I initialize DataManager object here?
For using IntentService, I have to use the constructor with no argument. Otherwise, I get an error "intentservice has no zero argument constructor". But I want to use DataManager object for fetching notification.
And you can check my whole approach too.

// }
@Override
protected void onHandleIntent(Intent intent) {
fetchNotification();
}
public void fetchNotification() {
// mSubscription = mDataManager.getNotification()
// .observeOn(AndroidSchedulers.mainThread())
// .subscribeOn(Schedulers.io())
// .subscribe(new Subscriber<NotificationTemplate>() {
// @Override
// public void onCompleted() {
// }
//
// @Override
// public void onError(Throwable e) {
// }
//
// @Override
// public void onNext(NotificationTemplate notificationTemplate) {
// NotificationUtil.createNotification(App.getContext(),
// notificationTemplate);
// }
// });
}
}
@@ -0,0 +1,94 @@
package com.mifos.objects;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by mayankjindal on 12/08/17.
*/
public class NotificationContent implements Parcelable {
@SerializedName("Subject")
String subject;
@SerializedName("Object")
String object;
@SerializedName("Action")
String action;
@SerializedName("Actor")
String actor;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.subject);
dest.writeString(this.object);
dest.writeString(this.action);
dest.writeString(this.actor);
}
public NotificationContent() {
}
protected NotificationContent(Parcel in) {
this.subject = in.readString();
this.object = in.readString();
this.action = in.readString();
this.actor = in.readString();
}
public static final Parcelable.Creator<NotificationContent> CREATOR =
new Parcelable.Creator<NotificationContent>() {
@Override
public NotificationContent createFromParcel(Parcel source) {
return new NotificationContent(source);
}
@Override
public NotificationContent[] newArray(int size) {
return new NotificationContent[size];
}
};
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.