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

Sync for Surveys #721

Merged
merged 1 commit into from Aug 18, 2017
Jump to file or symbol
Failed to load files and symbols.
+1,633 −41
Diff settings

Always

Just for now

@@ -127,6 +127,10 @@
android:label="@string/sync_loanrepayments" android:label="@string/sync_loanrepayments"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".SettingsActivity"
android:label="@string/settings"
android:screenOrientation="portrait" />
<activity <activity
android:name=".offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity" android:name=".offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity"
android:label="@string/sync_savingsaccounttransactions" android:label="@string/sync_savingsaccounttransactions"
@@ -2,9 +2,13 @@
import com.mifos.api.BaseApiManager; import com.mifos.api.BaseApiManager;
import com.mifos.api.local.databasehelper.DatabaseHelperSurveys; import com.mifos.api.local.databasehelper.DatabaseHelperSurveys;
import com.mifos.objects.survey.QuestionDatas;
import com.mifos.objects.survey.ResponseDatas;
import com.mifos.objects.survey.Scorecard; import com.mifos.objects.survey.Scorecard;
import com.mifos.objects.survey.Survey; import com.mifos.objects.survey.Survey;
import com.mifos.utils.PrefManager;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@@ -40,7 +44,45 @@ public DataManagerSurveys(BaseApiManager baseApiManager,
* @return Observable<List<Survey>> * @return Observable<List<Survey>>
*/ */
public Observable<List<Survey>> getAllSurvey() { public Observable<List<Survey>> getAllSurvey() {
return mBaseApiManager.getSurveyApi().getAllSurveys(); switch (PrefManager.getUserStatus()) {
case 0:
return mBaseApiManager.getSurveyApi().getAllSurveys();
case 1:
return mDatabaseHelperSurveys.readAllSurveys();
default:
List<Survey> defaultSurveyList = new ArrayList<Survey>();
return Observable.just(defaultSurveyList);
}
}
/**
* This method call the DatabaseHelperSurveys Helper and mDatabaseHelperSurveys.readAllSurveys()
* read the all Surveys from the Database Survey table and returns the List<Survey>.
*
* @return List<Survey>
*/
public Observable<List<Survey>> getDatabaseSurveys() {
return mDatabaseHelperSurveys.readAllSurveys();
}
/**
* This method call the DatabaseHelperSurveys Helper and
* mDatabaseHelperSurveys.getQuestionDatas() read the all QuestionDatas
* from the Database QuestionDatas table and returns the List<QuestionDatas>.
* @return List<QuestionDatas>
*/
public Observable<List<QuestionDatas>> getDatabaseQuestionDatas(int surveyId) {
return mDatabaseHelperSurveys.getQuestionDatas(surveyId);
}
/**
* This method call the DatabaseHelperSurveys Helper and
* mDatabaseHelperSurveys.getResponseDatas() read the all ResponseDatas
* from the Database ResponseDatas table and returns the List<ResponseDatas>.
* @return List<ResponseDatas>
*/
public Observable<List<ResponseDatas>> getDatabaseResponseDatas(int questionId) {
return mDatabaseHelperSurveys.getResponseDatas(questionId);
} }
@@ -58,4 +100,36 @@ public DataManagerSurveys(BaseApiManager baseApiManager,
public Observable<Survey> getSurvey(int surveyId) { public Observable<Survey> getSurvey(int surveyId) {
return mBaseApiManager.getSurveyApi().getSurvey(surveyId); return mBaseApiManager.getSurveyApi().getSurvey(surveyId);
} }
/**
* This method save the single Survey in Database.
*
* @param survey Survey
* @return Survey
*/
public Observable<Survey> syncSurveyInDatabase(Survey survey) {
return mDatabaseHelperSurveys.saveSurvey(survey);
}
/**
* This method save the single QuestionDatas in Database.
*
* @param questionDatas QuestionDatas
* @return QuestionDatas
*/
public Observable<QuestionDatas> syncQuestionDataInDatabase(int surveyId,
QuestionDatas questionDatas) {
return mDatabaseHelperSurveys.saveQuestionData(surveyId, questionDatas);
}
/**
* This method save the single ResponseDatas in Database.
*
* @param responseDatas ResponseDatas
* @return ResponseDatas
*/
public Observable<ResponseDatas> syncResponseDataInDatabase(int questionId,
ResponseDatas responseDatas) {
return mDatabaseHelperSurveys.saveResponseData(questionId, responseDatas);
}
} }
@@ -1,8 +1,22 @@
package com.mifos.api.local.databasehelper; package com.mifos.api.local.databasehelper;
import com.mifos.objects.survey.QuestionDatas;
import com.mifos.objects.survey.QuestionDatas_Table;
import com.mifos.objects.survey.ResponseDatas;
import com.mifos.objects.survey.ResponseDatas_Table;
import com.mifos.objects.survey.Survey;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import rx.Observable;
import rx.functions.Func0;
import static com.raizlabs.android.dbflow.sql.language.SQLite.select;
/** /**
* Created by Rajan Maurya on 22/08/16. * Created by Rajan Maurya on 22/08/16.
*/ */
@@ -13,4 +27,116 @@
public DatabaseHelperSurveys() { public DatabaseHelperSurveys() {
} }
/**
* This Method save the single Survey in Database with SurveyId as Primary Id
*
* @param survey Survey
* @return saved Survey
*/
public Observable<Survey> saveSurvey(final Survey survey) {
return Observable.defer(new Func0<Observable<Survey>>() {
@Override
public Observable<Survey> call() {
//Saving Survey in Database
survey.save();
return Observable.just(survey);
}
});
}
/**
* This Method save the single QuestionDatas in Database
*
* @param surveyId int, questionDatas QuestionDatas
* @return saved QuestionDatas
*/
public Observable<QuestionDatas> saveQuestionData(final int surveyId,
final QuestionDatas questionDatas) {
return Observable.defer(new Func0<Observable<QuestionDatas>>() {
@Override
public Observable<QuestionDatas> call() {
//Saving QuestionDatas in Database
questionDatas.setSurveyId(surveyId);
questionDatas.save();
return Observable.just(questionDatas);
}
});
}
/**
* This Method save the single ResponseDatas in Database
*
* @param questionId int, responseDatas ResponseDatas
* @return saved ResponseDatas
*/
public Observable<ResponseDatas> saveResponseData(final int questionId,
final ResponseDatas responseDatas) {
return Observable.defer(new Func0<Observable<ResponseDatas>>() {
@Override
public Observable<ResponseDatas> call() {
//Saving ResponseDatas in Database
responseDatas.setQuestionId(questionId);
responseDatas.save();
return Observable.just(responseDatas);
}
});
}
/**
* Reading All surveys from Database table of Survey and return the SurveyList
*
* @return List Of Surveys
*/
public Observable<List<Survey>> readAllSurveys() {
return Observable.defer(new Func0<Observable<List<Survey>>>() {
@Override
public Observable<List<Survey>> call() {
List<Survey> surveyList = select()
.from(Survey.class)
.queryList();
return Observable.just(surveyList);
}
});
}
/**
* Reading All QuestionDatas from Database table of QuestionDatas
* and return the QuestionDatasList
* @return List Of QuestionDatas
*/
public Observable<List<QuestionDatas>> getQuestionDatas(final int surveyId) {
return Observable.defer(new Func0<Observable<List<QuestionDatas>>>() {
@Override
public Observable<List<QuestionDatas>> call() {
List<QuestionDatas> questionDatas = select()
.from(QuestionDatas.class)
.where(QuestionDatas_Table.surveyId.eq(surveyId))
.orderBy(QuestionDatas_Table.sequenceNo, true)
.queryList();
return Observable.just(questionDatas);
}
});
}
/**
* Reading All ResponseDatas from Database table of ResponseDatas
* and return the ResponseDatasList
* @return List Of ResponseDatas
*/
public Observable<List<ResponseDatas>> getResponseDatas(final int questionId) {
return Observable.defer(new Func0<Observable<List<ResponseDatas>>>() {
@Override
public Observable<List<ResponseDatas>> call() {
List<ResponseDatas> responseDatas = select()
.from(ResponseDatas.class)
.where(ResponseDatas_Table.questionId.eq(questionId))
.orderBy(ResponseDatas_Table.sequenceNo, true)
.queryList();
return Observable.just(responseDatas);
}
});
}
} }
@@ -0,0 +1,20 @@
package com.mifos.mifosxdroid;
import android.os.Bundle;
import com.mifos.mifosxdroid.core.MifosBaseActivity;
/**
* Created by mayankjindal on 22/07/17.
*/
public class SettingsActivity extends MifosBaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toolbar_container);
showBackButton();
getFragmentManager().beginTransaction()
.replace(R.id.container, new SettingsFragment())
.commit();
}
}
@@ -0,0 +1,56 @@
package com.mifos.mifosxdroid;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;;
import com.mifos.mifosxdroid.core.MifosBaseFragment;
import com.mifos.mifosxdroid.dialogfragments.syncsurveysdialog.SyncSurveysDialogFragment;
import com.mifos.objects.survey.Survey;
import com.mifos.utils.FragmentConstants;
import java.util.List;
/**
* Created by mayankjindal on 22/07/17.
*/
public class SettingsFragment extends PreferenceFragment {
SwitchPreference mEnableSyncSurvey;
public static SettingsFragment newInstance() {
SettingsFragment fragment = new SettingsFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
mEnableSyncSurvey = (SwitchPreference)
findPreference(getResources().getString(R.string.sync_survey));
mEnableSyncSurvey.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (((Boolean) newValue)) {
SyncSurveysDialogFragment syncSurveysDialogFragment =
SyncSurveysDialogFragment.newInstance();
FragmentTransaction fragmentTransaction =
getFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(FragmentConstants.FRAG_SURVEYS_SYNC);
syncSurveysDialogFragment.setCancelable(false);
syncSurveysDialogFragment.show(fragmentTransaction,
getResources().getString(R.string.sync_clients));
}
return true;
}
});
}
}
@@ -11,6 +11,7 @@
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.mifos.mifosxdroid.R; import com.mifos.mifosxdroid.R;
@@ -63,16 +64,22 @@ public View getView(int i, View view, ViewGroup viewGroup) {
viewHolder = (ViewHolder) view.getTag(); viewHolder = (ViewHolder) view.getTag();
} }
final Survey survey = listSurvey.get(i); final Survey survey = listSurvey.get(i);
viewHolder.tv_survey_name.setText(survey.getName()); viewHolder.tvSurveyName.setText(survey.getName());
viewHolder.tv_description.setText(survey.getDescription()); viewHolder.tvDescription.setText(survey.getDescription());
viewHolder.ivSyncStatus
.setVisibility(survey.isSync() ? View.VISIBLE : View.INVISIBLE);
return view; return view;
} }
public static class ViewHolder { public static class ViewHolder {
@BindView(R.id.tv_survey_name) @BindView(R.id.tv_survey_name)
TextView tv_survey_name; TextView tvSurveyName;
@BindView(R.id.tv_description) @BindView(R.id.tv_description)
TextView tv_description; TextView tvDescription;
@BindView(R.id.iv_sync_status)
ImageView ivSyncStatus;
public ViewHolder(View view) { public ViewHolder(View view) {
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.