mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-07-01 05:14:17 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,56 @@
|
|||
package com.adins.mss.svy.tool;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.adins.mss.base.authentication.Authentication;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.foundation.db.DaoOpenHelper;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
//import android.content.SharedPreferences;
|
||||
|
||||
public class CopyDb extends DaoOpenHelper {
|
||||
|
||||
Context context;
|
||||
|
||||
public CopyDb(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void copyTable(){
|
||||
|
||||
final String DBDestination = "/data/data/" + context.getPackageName() + "/databases/msmdb";
|
||||
try(OutputStream os = new FileOutputStream(DBDestination);
|
||||
InputStream is = context.getAssets().open("msmdb")){
|
||||
// File file = new File("/data/data/" + context.getPackageName() + "/databases/", "msmdb");
|
||||
ObscuredSharedPreferences pref = ObscuredSharedPreferences.getPrefs(context,Authentication.SHARED_PREF, Context.MODE_PRIVATE);
|
||||
boolean isDbWrite = pref.getBoolean(Authentication.SHARED_PREF_KEY_DB_SAVED, false);
|
||||
if(!isDbWrite){
|
||||
|
||||
byte [] buffer = new byte[1024];
|
||||
int length;
|
||||
while((length = is.read(buffer)) > 0){
|
||||
os.write(buffer, 0, length);
|
||||
}
|
||||
os.flush();
|
||||
if(Global.IS_DEV)
|
||||
System.out.println("Copy db from assets success");
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = pref.edit();
|
||||
sharedPrefEditor.putBoolean(Authentication.SHARED_PREF_KEY_DB_SAVED, true);
|
||||
sharedPrefEditor.apply();
|
||||
} else {
|
||||
if(Global.IS_DEV)
|
||||
System.out.println("Database msmdb already exist");
|
||||
}
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
|
@ -0,0 +1,105 @@
|
|||
package com.adins.mss.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.adins.mss.foundation.dialog.DialogManager;
|
||||
import com.adins.mss.foundation.security.storepreferences.ObscuredSharedPreferences;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class ServerLinkActivity extends AppCompatActivity implements OnClickListener {
|
||||
|
||||
private FirebaseAnalytics screenName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.new_server_link_activity);
|
||||
|
||||
screenName = FirebaseAnalytics.getInstance(this);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setTitleTextColor(getResources().getColor(R.color.fontColorWhite));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ACRA.getErrorReporter().putCustomData("LAST_CLASS_ACCESSED", getClass().getSimpleName());
|
||||
EditText txtServerLink = (EditText) findViewById(R.id.txtServerLink);
|
||||
txtServerLink.setText(GlobalData.getSharedGlobalData().getUrlMain());
|
||||
|
||||
Button btnLogin = (Button) findViewById(R.id.btnSaveLink);
|
||||
btnLogin.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
ServerLinkActivity.this.finish();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
|
||||
super.onResume();
|
||||
//Set Firebase screen name
|
||||
screenName.setCurrentScreen(this, getString(R.string.screen_name_server_link), null);
|
||||
|
||||
try {
|
||||
DialogManager.showGPSAlert(this);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
Context context = newBase;
|
||||
Locale locale;
|
||||
try{
|
||||
locale = new Locale(GlobalData.getSharedGlobalData().getLocale());
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} catch (Exception e) {
|
||||
locale = new Locale(LocaleHelper.ENGLSIH);
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} finally {
|
||||
super.attachBaseContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
Button btn = (Button) v;
|
||||
int id = btn.getId();
|
||||
if (R.id.btnSaveLink == id) {
|
||||
EditText txtServerLink = (EditText) findViewById(R.id.txtServerLink);
|
||||
String serverLink = txtServerLink.getText().toString().trim();
|
||||
|
||||
|
||||
GlobalData.getSharedGlobalData().setUrlMain(serverLink);
|
||||
GlobalData.getSharedGlobalData().reloadUrl(this.getApplicationContext());
|
||||
|
||||
//Gigin ~ set URL Header Di Global.URL_HEADER tanpa "m/"
|
||||
ObscuredSharedPreferences sharedPref = ObscuredSharedPreferences.getPrefs(getApplicationContext(),
|
||||
"GlobalData", Context.MODE_PRIVATE);
|
||||
|
||||
ObscuredSharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
|
||||
sharedPrefEditor.putString("URL_HEADER", serverLink);
|
||||
sharedPrefEditor.commit();
|
||||
|
||||
ServerLinkActivity.this.finish();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* jets3t : Java Extra-Tasty S3 Toolkit (for Amazon S3 online storage service)
|
||||
* This is a java.net project, see https://jets3t.dev.java.net/
|
||||
*
|
||||
* Copyright 2006 James Murty
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.adins.mss.base.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* Formats numeric byte values into human-readable strings.
|
||||
*
|
||||
* @author James Murty
|
||||
*/
|
||||
public class ByteFormatter {
|
||||
|
||||
private static String gigabyteSuffix = " Gigabytes";
|
||||
private static String megabyteSuffix = " Megabytes";
|
||||
private static String kilobyteSuffix = " Kilobytes";
|
||||
private static String byteSuffix = " Bytes";
|
||||
private static NumberFormat nf = new DecimalFormat("#,###.##");
|
||||
|
||||
/**
|
||||
* Converts a byte size into a human-readable string, such as "1.43 MB" or "27 KB".
|
||||
* The values used are based on powers of 1024, ie 1 KB = 1024 bytes, not 1000 bytes.
|
||||
*
|
||||
* @param byteSize the byte size of some item
|
||||
* @return a human-readable description of the byte size
|
||||
*/
|
||||
public static String formatByteSize(long byteSize) {
|
||||
String result = null;
|
||||
try {
|
||||
if (byteSize > Math.pow(1024, 3)) {
|
||||
// Report gigabytes
|
||||
result = nf.format(new Double(byteSize / Math.pow(1024, 3))) + gigabyteSuffix;
|
||||
} else if (byteSize > Math.pow(1024, 2)) {
|
||||
// Report megabytes
|
||||
result = nf.format(new Double(byteSize / Math.pow(1024, 2))) + megabyteSuffix;
|
||||
} else if (byteSize > 1024) {
|
||||
// Report kilobytes
|
||||
result = nf.format(new Double(byteSize / Math.pow(1024, 1))) + kilobyteSuffix;
|
||||
} else if (byteSize >= 0) {
|
||||
// Report bytes
|
||||
result = byteSize + byteSuffix;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return byteSize + byteSuffix;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
package com.adins.mss.base.dialogfragments;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.PrintActivity;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.dynamicform.SendResultActivity;
|
||||
import com.adins.mss.base.util.ByteFormatter;
|
||||
import com.adins.mss.base.util.SecondFormatter;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Scheme;
|
||||
import com.adins.mss.dao.TaskH;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.SchemeDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskDDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.TaskHDataAccess;
|
||||
|
||||
import zj.com.cn.bluetooth.sdk.Main_Activity1;
|
||||
|
||||
public class SendResultDialog extends DialogFragment {
|
||||
|
||||
public static String rvNumber = null;
|
||||
private static SendResultActivity INSTANCE = null;
|
||||
TextView txtResult;
|
||||
TextView txtTimeSent;
|
||||
TextView txtDateSize;
|
||||
ImageView imgHeader;
|
||||
private String taskId;
|
||||
//private boolean isPrintable;
|
||||
private boolean error;
|
||||
private Button btnOk;
|
||||
private Button btnPrintPage;
|
||||
private NewMainActivity mainActivity;
|
||||
|
||||
public SendResultDialog() {
|
||||
}
|
||||
|
||||
public static SendResultDialog newInstance() {
|
||||
SendResultDialog fragment = new SendResultDialog();
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.new_dialog_send_result, container, false);
|
||||
|
||||
rvNumber = null;
|
||||
txtResult = (TextView) v.findViewById(com.adins.mss.base.R.id.txtResult);
|
||||
txtTimeSent = (TextView) v.findViewById(com.adins.mss.base.R.id.txtTimeSent);
|
||||
txtDateSize = (TextView) v.findViewById(com.adins.mss.base.R.id.txtDataSize);
|
||||
imgHeader = (ImageView) v.findViewById(com.adins.mss.base.R.id.imgHeader);
|
||||
|
||||
btnPrintPage = (Button) v.findViewById(com.adins.mss.base.R.id.btnPrintPage);
|
||||
|
||||
btnOk = (Button) v.findViewById(com.adins.mss.base.R.id.btnOK);
|
||||
btnOk.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mainActivity.gotoTimeline();
|
||||
}
|
||||
});
|
||||
btnPrintPage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!GlobalData.getSharedGlobalData().getListPrinter().isEmpty()) {
|
||||
final String[] listPrinterDevice = GlobalData.getSharedGlobalData().getListPrinter().split(",");
|
||||
CharSequence printers[] = new CharSequence[listPrinterDevice.length];
|
||||
for (int i = 0; i < listPrinterDevice.length; i++) {
|
||||
String printer[] = listPrinterDevice[i].split("@");
|
||||
printers[i] = printer[0];
|
||||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle("Choose Printer Driver");
|
||||
builder.setItems(printers, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String printer[] = listPrinterDevice[which].split("@");
|
||||
if ("0".equalsIgnoreCase(printer[1])) {
|
||||
Intent intent = new Intent(getContext(), PrintActivity.class);
|
||||
//intent.putExtra(name, value);
|
||||
intent.putExtra("taskId", taskId);
|
||||
intent.putExtra("source", "submit");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), Main_Activity1.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("taskId", taskId);
|
||||
intent.putExtra("source", "submit");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
Bundle extras = getArguments();
|
||||
|
||||
this.error = extras.getBoolean(Global.BUND_KEY_SURVEY_ERROR);
|
||||
if (error) {
|
||||
String errMessage = extras.getString(Global.BUND_KEY_SURVEY_ERROR_MSG);
|
||||
if (errMessage == null)
|
||||
txtResult.setText(extras.getString(Global.BUND_KEY_SEND_RESULT));
|
||||
else txtResult.setText(errMessage);
|
||||
imgHeader.setImageResource(com.adins.mss.base.R.drawable.ic_failed);
|
||||
this.taskId = extras.getString(Global.BUND_KEY_TASK_ID);
|
||||
if (taskId.contains("refused"))
|
||||
taskId = "Connection Refused";
|
||||
txtTimeSent.setText(taskId);
|
||||
btnPrintPage.setVisibility(View.GONE);
|
||||
txtDateSize.setVisibility(View.GONE);
|
||||
if (taskId.contains("been deleted")) {
|
||||
imgHeader.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String result = extras.getString(Global.BUND_KEY_SEND_RESULT);
|
||||
try {
|
||||
this.taskId = extras.getString(Global.BUND_KEY_TASK_ID);
|
||||
String time = extras.getString(Global.BUND_KEY_SEND_TIME);
|
||||
String seconds = SecondFormatter.secondsToString(Long.parseLong(time));
|
||||
String mTime = getString(com.adins.mss.base.R.string.time) + seconds;
|
||||
|
||||
String size = extras.getString(Global.BUND_KEY_SEND_SIZE);
|
||||
String bytes = ByteFormatter.formatByteSize(Long.parseLong(size));
|
||||
String mSize = getString(com.adins.mss.base.R.string.size) + bytes;
|
||||
|
||||
txtTimeSent.setText(mTime);
|
||||
txtDateSize.setText(mSize);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
txtTimeSent.setVisibility(View.GONE);
|
||||
txtDateSize.setVisibility(View.GONE);
|
||||
}
|
||||
txtResult.setText(result);
|
||||
|
||||
try {
|
||||
TaskH taskH = TaskHDataAccess.getOneTaskHeader(getContext(), taskId);
|
||||
Scheme scheme = SchemeDataAccess.getOne(getContext(), taskH.getUuid_scheme());
|
||||
if (scheme != null) {
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
boolean isTaskPaid = TaskDDataAccess.isTaskPaid(getContext(),
|
||||
uuidUser, taskH.getUuid_task_h());
|
||||
boolean isRVinFront = GeneralParameterDataAccess.isRvInFrontEnable(getContext(), uuidUser);
|
||||
if (isRVinFront) {
|
||||
btnPrintPage.setVisibility(View.GONE);
|
||||
} else if (!scheme.getIs_printable().equals("1") || !isTaskPaid) {
|
||||
btnPrintPage.setVisibility(View.GONE);
|
||||
} else {
|
||||
btnPrintPage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (rvNumber != null && !rvNumber.isEmpty()) {
|
||||
btnPrintPage.setVisibility(View.GONE);
|
||||
}
|
||||
Utility.freeMemory();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.adins.mss.odr.accounts;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Account;
|
||||
import com.adins.mss.foundation.db.dataaccess.AccountDataAccess;
|
||||
import com.adins.mss.odr.R;
|
||||
import com.adins.mss.odr.accounts.adapter.AccountListAdapter;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by muhammad.aap on 11/27/2018.
|
||||
*/
|
||||
|
||||
public class FragmentAccountList extends Fragment {
|
||||
private ArrayList<String> uuidAccounts;
|
||||
private List<Account> accountList;
|
||||
private RecyclerView list;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private RecyclerView.Adapter adapter;
|
||||
private FirebaseAnalytics screenName;
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Utility.freeMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_new_account_list, container, false);
|
||||
screenName = FirebaseAnalytics.getInstance(getActivity());
|
||||
uuidAccounts = new ArrayList<>();
|
||||
Bundle bundle = getArguments();
|
||||
uuidAccounts = bundle.getStringArrayList(Global.BUND_KEY_ACCOUNT_ID);
|
||||
accountList = new ArrayList<>();
|
||||
if (uuidAccounts != null) {
|
||||
for (String uuid : uuidAccounts) {
|
||||
Account account = AccountDataAccess.getOne(getActivity(), uuid);
|
||||
accountList.add(account);
|
||||
}
|
||||
}
|
||||
|
||||
list = (RecyclerView) view.findViewById(R.id.accountList);
|
||||
layoutManager = new LinearLayoutManager(getActivity());
|
||||
list.setLayoutManager(layoutManager);
|
||||
adapter = new AccountListAdapter(getActivity(), accountList);
|
||||
list.setAdapter(adapter);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//Set Firebase screen name
|
||||
screenName.setCurrentScreen(getActivity(), getString(R.string.screen_name_account_list), null);
|
||||
getActivity().setTitle(getString(com.adins.mss.base.R.string.title_mn_account));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
// mIndicator.cleanup();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
package com.adins.mss.main;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.adins.mss.base.AppContext;
|
||||
import com.adins.mss.base.DeveloperOptionActivity;
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.LoginActivity;
|
||||
import com.adins.mss.base.ServerLinkActivity;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.timeline.NewTimelineFragment;
|
||||
import com.adins.mss.coll.BuildConfig;
|
||||
import com.adins.mss.coll.NewMCMainActivity;
|
||||
import com.adins.mss.coll.R;
|
||||
import com.adins.mss.coll.services.FirebaseMessagingService;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Broadcast;
|
||||
import com.adins.mss.foundation.config.ConfigFileReader;
|
||||
import com.adins.mss.foundation.db.dataaccess.BroadcastDataAccess;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ACRAConfiguration;
|
||||
import org.acra.ACRAConfigurationException;
|
||||
import org.acra.ReportField;
|
||||
import org.acra.ReportingInteractionMode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by dian.ina on 04/06/2015.
|
||||
*/
|
||||
|
||||
//@ReportsCrashes(
|
||||
// formUri = "http://app.ad-ins.com:5984/acra-demotest/_design/acra-storage/_update/report",
|
||||
// reportType = org.acra.sender.HttpSender.Type.JSON,
|
||||
// httpMethod = org.acra.sender.HttpSender.Method.PUT,
|
||||
// formUriBasicAuthLogin="admin",
|
||||
// formUriBasicAuthPassword="12345",
|
||||
// customReportContent = {
|
||||
// ReportField.APP_VERSION_CODE,
|
||||
// ReportField.APP_VERSION_NAME,
|
||||
// ReportField.ANDROID_VERSION,
|
||||
// ReportField.INSTALLATION_ID,
|
||||
// ReportField.PACKAGE_NAME,
|
||||
// ReportField.REPORT_ID,
|
||||
// ReportField.BUILD,
|
||||
// ReportField.STACK_TRACE,
|
||||
// ReportField.AVAILABLE_MEM_SIZE,
|
||||
// ReportField.TOTAL_MEM_SIZE,
|
||||
// ReportField.SETTINGS_SECURE,
|
||||
// ReportField.DISPLAY,
|
||||
// ReportField.CUSTOM_DATA
|
||||
// },
|
||||
// mode = ReportingInteractionMode.TOAST,
|
||||
// resToastText = R.string.toast_crash
|
||||
//)
|
||||
|
||||
public class MSMApplication extends AppContext {
|
||||
private BroadcastReceiver mReceiver;
|
||||
private List<Broadcast> broadcastList;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
context = getApplicationContext();
|
||||
|
||||
final ACRAConfiguration config = new ACRAConfiguration();
|
||||
if(BuildConfig.FLAVOR.contains("prod")){
|
||||
config.setFormUri("http://app.ad-ins.com:5984/acra-aitmss-prod/_design/acra-storage/_update/report");
|
||||
}else{
|
||||
config.setFormUri("http://app.ad-ins.com:5984/acra-aitmss-dev/_design/acra-storage/_update/report");
|
||||
}
|
||||
config.setReportType(org.acra.sender.HttpSender.Type.JSON);
|
||||
config.setHttpMethod(org.acra.sender.HttpSender.Method.PUT);
|
||||
config.setFormUriBasicAuthLogin("admin");
|
||||
config.setFormUriBasicAuthPassword("12345");
|
||||
ReportField[] customReportContent = {
|
||||
ReportField.APP_VERSION_CODE,
|
||||
ReportField.APP_VERSION_NAME,
|
||||
ReportField.ANDROID_VERSION,
|
||||
ReportField.INSTALLATION_ID,
|
||||
ReportField.PACKAGE_NAME,
|
||||
ReportField.REPORT_ID,
|
||||
ReportField.BUILD,
|
||||
ReportField.STACK_TRACE,
|
||||
ReportField.AVAILABLE_MEM_SIZE,
|
||||
ReportField.TOTAL_MEM_SIZE,
|
||||
ReportField.SETTINGS_SECURE,
|
||||
ReportField.DISPLAY,
|
||||
ReportField.CUSTOM_DATA,
|
||||
ReportField.SHARED_PREFERENCES
|
||||
};
|
||||
config.setCustomReportContent(customReportContent);
|
||||
|
||||
//disable acra => set acra custom preference sesuai app.properties
|
||||
Properties properties = ConfigFileReader.propertiesFromFile(this, GlobalData.PROPERTY_FILENAME);
|
||||
boolean disableAcra = Boolean.parseBoolean(properties.getProperty(GlobalData.PROP_DISABLE_ACRA));
|
||||
Global.ACRA_DISABLED = disableAcra;
|
||||
String acraCustomPrefName = "ACRACUSTOMPREF";
|
||||
SharedPreferences acracustompref = getSharedPreferences(acraCustomPrefName, Context.MODE_PRIVATE);
|
||||
acracustompref.edit().putBoolean(ACRA.PREF_DISABLE_ACRA,disableAcra).commit();
|
||||
|
||||
config.setSharedPreferenceName(acraCustomPrefName);
|
||||
config.setSharedPreferenceMode(Context.MODE_PRIVATE);
|
||||
|
||||
try {
|
||||
config.setMode(ReportingInteractionMode.TOAST);
|
||||
} catch (ACRAConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
config.setResToastText(R.string.toast_crash);
|
||||
|
||||
ACRA.init(this, config);
|
||||
|
||||
//setting firebase crashlytic instance
|
||||
FirebaseApp.initializeApp(this);
|
||||
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
|
||||
FireCrash.setInstance(FirebaseCrashlytics.getInstance());
|
||||
|
||||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(final Activity activity) {
|
||||
context = activity;
|
||||
broadcastList = BroadcastDataAccess.getAllNotShown(activity);
|
||||
|
||||
showNewBroadcast();
|
||||
|
||||
mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String title = intent.getStringExtra(FirebaseMessagingService.KEY_BROADCAST_MESSAGE_TITLE);
|
||||
if(null == title || title.length() < 1){
|
||||
title = getApplicationContext().getString(com.adins.mss.base.R.string.push_notification);
|
||||
}
|
||||
|
||||
final String broadcastId = intent.getStringExtra(FirebaseMessagingService.KEY_BROADCAST_MESSAGE_ID);
|
||||
String notif = intent.getStringExtra(FirebaseMessagingService.KEY_BROADCAST_MESSAGE_MESSAGE);
|
||||
|
||||
final NiftyDialogBuilder ndb = NiftyDialogBuilder.getInstance(activity);
|
||||
ndb.withTitle(title)
|
||||
.withMessage(HtmlCompat.fromHtml(notif, HtmlCompat.FROM_HTML_MODE_LEGACY))
|
||||
.withButton1Text(context.getString(R.string.btnOk))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
NewTimelineFragment.SendUpdateNotification sendUpdateNotif = new NewTimelineFragment.SendUpdateNotification(activity, uuidUser, broadcastId);
|
||||
sendUpdateNotif.execute();
|
||||
ndb.dismiss();
|
||||
onBroadcastDismissed(broadcastId);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
};
|
||||
|
||||
if(shouldActivityShowBroadcast(activity)){
|
||||
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
|
||||
manager.registerReceiver(mReceiver, new IntentFilter(FirebaseMessagingService.INTENT_BROADCAST_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(activity);
|
||||
manager.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean shouldActivityShowBroadcast(Activity activity){
|
||||
return !(activity instanceof LoginActivity
|
||||
|| activity instanceof ServerLinkActivity
|
||||
|| activity instanceof DeveloperOptionActivity
|
||||
);
|
||||
}
|
||||
|
||||
private void showNewBroadcast(){
|
||||
if(broadcastList != null && !broadcastList.isEmpty()){
|
||||
Broadcast broadcast = broadcastList.remove(0);
|
||||
showBroadcast(broadcast);
|
||||
}
|
||||
}
|
||||
|
||||
private void showBroadcast(final Broadcast broadcast){
|
||||
String title = broadcast.getTitle();
|
||||
if(null == title || title.length() < 1){
|
||||
title = getApplicationContext().getString(com.adins.mss.base.R.string.push_notification);
|
||||
}
|
||||
|
||||
final NiftyDialogBuilder ndb = NiftyDialogBuilder.getInstance(context);
|
||||
ndb.withTitle(title)
|
||||
.withMessage(HtmlCompat.fromHtml(broadcast.getMessage(), HtmlCompat.FROM_HTML_MODE_LEGACY))
|
||||
.withButton1Text(context.getString(R.string.btnOk))
|
||||
.setButton1Click(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
String uuidNotification = broadcast.getUuid_broadcast();
|
||||
String uuidUser = GlobalData.getSharedGlobalData().getUser().getUuid_user();
|
||||
NewTimelineFragment.SendUpdateNotification sendUpdateNotif = new NewTimelineFragment.SendUpdateNotification(context, uuidUser, uuidNotification);
|
||||
sendUpdateNotif.execute();
|
||||
ndb.dismiss();
|
||||
onBroadcastDismissed(broadcast.getUuid_broadcast());
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onBroadcastDismissed(String uuidBroadcast){
|
||||
Broadcast broadcast = BroadcastDataAccess.getById(context, uuidBroadcast);
|
||||
broadcast.setIs_shown(true);
|
||||
BroadcastDataAccess.addOrUpdate(context, broadcast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getHomeClass() {
|
||||
return NewMCMainActivity.class;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue