LeOS-Genesis/app/src/main/java/com/darkweb/genesissearchengine/pluginManager/messageManager.java

489 lines
19 KiB
Java
Raw Normal View History

2020-01-24 16:23:31 +01:00
package com.darkweb.genesissearchengine.pluginManager;
import android.annotation.SuppressLint;
2020-10-20 16:55:08 +02:00
import android.app.Dialog;
import android.content.Context;
2020-01-24 16:23:31 +01:00
import android.content.Intent;
2020-10-20 16:55:08 +02:00
import android.graphics.drawable.ColorDrawable;
2020-01-24 16:23:31 +01:00
import android.net.Uri;
import android.os.Handler;
import android.view.Gravity;
2020-11-27 12:40:46 +01:00
import android.view.LayoutInflater;
import android.view.View;
2020-10-20 16:55:08 +02:00
import android.view.inputmethod.InputMethodManager;
2020-01-24 16:23:31 +01:00
import android.widget.EditText;
2020-10-20 16:55:08 +02:00
import android.widget.RatingBar;
import android.widget.TextView;
2020-11-27 12:40:46 +01:00
import android.widget.Toast;
2020-01-24 16:23:31 +01:00
import androidx.appcompat.app.AppCompatActivity;
2020-10-20 16:55:08 +02:00
import com.darkweb.genesissearchengine.appManager.activityContextManager;
2020-01-24 16:23:31 +01:00
import com.darkweb.genesissearchengine.constants.constants;
import com.darkweb.genesissearchengine.constants.enums;
import com.darkweb.genesissearchengine.constants.status;
import com.darkweb.genesissearchengine.constants.strings;
import com.darkweb.genesissearchengine.helperManager.eventObserver;
import com.darkweb.genesissearchengine.helperManager.helperMethod;
import com.example.myapplication.R;
import java.io.File;
import java.util.Collections;
import java.util.List;
2020-11-27 12:40:46 +01:00
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
2020-01-24 16:23:31 +01:00
class messageManager
{
/*Private Variables*/
2020-11-27 12:40:46 +01:00
private List<Object> data;
2020-01-24 16:23:31 +01:00
private AppCompatActivity app_context;
private eventObserver.eventListener event;
2020-10-20 16:55:08 +02:00
Dialog dialog = null;
2020-01-24 16:23:31 +01:00
/*Initializations*/
2020-11-27 12:40:46 +01:00
private void initializeDialog(int pLayout,int pGravity,int pFlag){
if(dialog!=null && dialog.isShowing()){
dialog.dismiss();
}
dialog = new Dialog(app_context);
dialog.getWindow().setGravity(pGravity);
dialog.getWindow().getAttributes().windowAnimations = R.style.dialiog_animation;
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setCancelable(true);
dialog.setContentView(pLayout);
dialog.show();
dialog.getWindow().clearFlags(pFlag);
}
2020-01-24 16:23:31 +01:00
messageManager(eventObserver.eventListener event)
{
this.event = event;
}
/*Helper Methods*/
private void welcomeMessage()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_welcome, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pOption1).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(constants.CONST_BLACK_MARKET_URL), enums.etype.welcome);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption2).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(constants.CONST_LEAKED_DOCUMENT_URL), enums.etype.welcome);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(constants.CONST_NEWS_URL), enums.etype.welcome);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption4).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(constants.CONST_SOFTWARE_URL), enums.etype.welcome);
dialog.dismiss();
});
2020-10-22 10:36:44 +02:00
dialog.findViewById(R.id.pOption5).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(constants.CONST_SOFTWARE_FINANCE), enums.etype.welcome);
dialog.dismiss();
});
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pOption6).setOnClickListener(v -> {
2020-10-22 10:36:44 +02:00
event.invokeObserver(Collections.singletonList(constants.CONST_COMMUNITIES), enums.etype.welcome);
2020-10-20 16:55:08 +02:00
dialog.dismiss();
});
2020-10-22 10:36:44 +02:00
dialog.findViewById(R.id.pDontShowAgain).setOnClickListener(v -> {
2020-10-20 16:55:08 +02:00
event.invokeObserver(null, enums.etype.cancel_welcome);
dialog.dismiss();
});
2020-01-24 16:23:31 +01:00
}
2020-11-11 13:11:13 +01:00
@SuppressLint("QueryPermissionsNeeded")
2020-01-24 16:23:31 +01:00
private void abiError()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_abi_error, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-11-11 13:11:13 +01:00
dialog.findViewById(R.id.pOption1).setOnClickListener(v -> {
2020-10-20 16:55:08 +02:00
dialog.dismiss();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(constants.CONST_GENESIS_UPDATE_URL + status.sAppCurrentABI));
if(browserIntent.resolveActivity(app_context.getPackageManager()) != null)
{
app_context.startActivity(browserIntent);
}else {
helperMethod.showToastMessage("Not Supported",app_context);
}
});
dialog.findViewById(R.id.pOption2).setOnClickListener(v -> {
dialog.dismiss();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(constants.CONST_PLAYSTORE_URL));
if(browserIntent.resolveActivity(app_context.getPackageManager()) != null)
{
app_context.startActivity(browserIntent);
}else {
helperMethod.showToastMessage("Playstore Not Found",app_context);
}
});
2020-01-24 16:23:31 +01:00
}
2020-10-20 16:55:08 +02:00
private void rateFailure()
2020-01-24 16:23:31 +01:00
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_rate_failure, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
final Handler handler = new Handler();
Runnable runnable = () -> {
try{
helperMethod.sendRateEmail(app_context);
}
catch (Exception ex){
2020-10-22 10:36:44 +02:00
createMessage(app_context,Collections.singletonList(app_context.getString(R.string.ALERT_NOT_SUPPORTED_MESSAGE)),enums.etype.on_not_support);
2020-10-20 16:55:08 +02:00
}
};
handler.postDelayed(runnable, 1000);
});
2020-01-24 16:23:31 +01:00
}
private void reportedSuccessfully()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_reported_successfully, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pNext).setOnClickListener(v -> dialog.dismiss());
2020-02-28 19:10:00 +01:00
}
private void notSupportMessage()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_not_supported, Gravity.BOTTOM, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
2020-01-24 16:23:31 +01:00
}
2020-11-11 13:11:13 +01:00
private void dataClearedSuccessfully()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_data_cleared, Gravity.BOTTOM, FLAG_DIM_BEHIND);
2020-11-11 13:11:13 +01:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
}
2020-11-27 12:40:46 +01:00
2020-01-24 16:23:31 +01:00
@SuppressLint("ResourceType")
private void bookmark()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_create_bookmark, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
EditText mBoomMarkTitle = dialog.findViewById(R.id.pBookmark);
dialog.setOnDismissListener(dialog -> {
final Handler handler = new Handler();
Runnable runnable = () -> {
helperMethod.hideKeyboard(activityContextManager.getInstance().getHomeController());
dialog.dismiss();
};
handler.postDelayed(runnable, 50);
});
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> {
dialog.dismiss();
helperMethod.hideKeyboard(activityContextManager.getInstance().getHomeController());
});
mBoomMarkTitle.requestFocus();
InputMethodManager imm = (InputMethodManager) app_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
helperMethod.hideKeyboard(app_context);
2020-11-27 12:40:46 +01:00
event.invokeObserver(Collections.singletonList(data.get(0).toString().replace("genesis.onion","boogle.store")+"split"+((EditText)dialog.findViewById(R.id.pBookmark)).getText().toString()), enums.etype.bookmark);
2020-10-20 16:55:08 +02:00
});
2020-01-24 16:23:31 +01:00
}
2020-10-20 16:55:08 +02:00
private void clearHistory()
2020-01-24 16:23:31 +01:00
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_clear_history, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
event.invokeObserver(null, enums.etype.clear_history);
});
2020-01-24 16:23:31 +01:00
}
private void clearBookmark()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_clear_bookmark, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
event.invokeObserver(null, enums.etype.clear_bookmark);
});
2020-01-24 16:23:31 +01:00
}
private void reportURL()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_report_url, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
final Handler handler = new Handler();
Runnable runnable = () -> createMessage(app_context,Collections.singletonList(strings.GENERIC_EMPTY_STR), enums.etype.reported_success);
handler.postDelayed(runnable, 1000);
});
2020-01-24 16:23:31 +01:00
}
2020-11-11 13:11:13 +01:00
@SuppressLint("QueryPermissionsNeeded")
2020-01-24 16:23:31 +01:00
private void rateApp()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_rate_us, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
RatingBar mRatingBar = dialog.findViewById(R.id.pRating);
if(mRatingBar.getRating()>=3){
event.invokeObserver(null, enums.etype.app_rated);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.darkweb.genesissearchengine"));
if(intent.resolveActivity(app_context.getPackageManager()) != null)
{
app_context.startActivity(intent);
}else {
helperMethod.showToastMessage("Playstore Not Found",app_context);
}
dialog.dismiss();
}else if(mRatingBar.getRating()>0) {
event.invokeObserver(null, enums.etype.app_rated);
final Handler handler = new Handler();
handler.postDelayed(() -> createMessage(app_context,Collections.singletonList(strings.GENERIC_EMPTY_STR), enums.etype.rate_failure), 1000);
dialog.dismiss();
}
});
2020-01-24 16:23:31 +01:00
}
private void downloadFile()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_download_file, Gravity.BOTTOM, FLAG_DIM_BEHIND);
2020-10-22 10:36:44 +02:00
((TextView)dialog.findViewById(R.id.pDescription)).setText((app_context.getString(R.string.ALERT_DOWNLOAD_MESSAGE) + data.get(0)));
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
2020-01-24 16:23:31 +01:00
}
@SuppressLint("ResourceAsColor")
private void downloadFileLongPress()
{
2020-11-27 12:40:46 +01:00
File f = new File(data.get(0).toString());
2020-01-24 16:23:31 +01:00
String name = f.getName();
2020-11-27 12:40:46 +01:00
String title = data.get(1).toString();
2020-01-24 16:23:31 +01:00
int size = name.length();
2020-11-11 13:11:13 +01:00
if(size>235){
size = 235;
2020-01-24 16:23:31 +01:00
}
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_file_longpress, Gravity.CENTER, FLAG_DIM_BEHIND);
((TextView)dialog.findViewById(R.id.pDescription)).setText((title + " | " + data.get(0).toString().substring(0,size)+"..."));
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pOption1).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.download_file_manual);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption2).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.open_link_current_tab);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
2020-01-24 16:23:31 +01:00
}
private void openURLLongPress()
{
2020-11-27 12:40:46 +01:00
int size = data.get(0).toString().length()-1;
String title = data.get(1).toString();
2020-01-24 16:23:31 +01:00
2020-11-11 13:11:13 +01:00
if(size>235){
size = 235;
2020-01-24 16:23:31 +01:00
}
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_url_longpress, Gravity.CENTER, FLAG_DIM_BEHIND);
((TextView)dialog.findViewById(R.id.pDescription)).setText((title + data.get(0).toString().substring(0,size)+"..."));
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pOption1).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.open_link_new_tab);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption2).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.open_link_current_tab);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
2020-02-28 19:10:00 +01:00
}
2020-01-24 16:23:31 +01:00
private void popupDownloadFull(){
2020-11-27 12:40:46 +01:00
String url = data.get(0).toString();
String file = data.get(1).toString();
String title = data.get(2).toString();
2020-01-24 16:23:31 +01:00
2020-10-22 10:36:44 +02:00
String data_local = app_context.getString(R.string.ALERT_LONG_URL_MESSAGE);
2020-01-24 16:23:31 +01:00
int size = url.length();
2020-11-11 13:11:13 +01:00
if(size>235){
size = 235;
2020-01-24 16:23:31 +01:00
}
int size1 = file.length();
2020-11-11 13:11:13 +01:00
if(size1>235){
size1 = 235;
2020-01-24 16:23:31 +01:00
}
if(!url.equals("")){
data_local = title + url.substring(0,size)+"...";
}
else if(!file.equals("")){
2020-11-11 13:11:13 +01:00
data_local = file.substring(0,size1)+"...";
}
String mTitle = title;
if(mTitle.length()<=1){
2020-11-27 12:40:46 +01:00
mTitle = data.get(0).toString().substring(0,size)+"...";
2020-01-24 16:23:31 +01:00
}
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_download_full, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-11-11 13:11:13 +01:00
((TextView)dialog.findViewById(R.id.pHeader)).setText(mTitle);
2020-10-20 16:55:08 +02:00
((TextView)dialog.findViewById(R.id.pDescription)).setText((data_local));
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pOption1).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.open_link_new_tab);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption2).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.open_link_current_tab);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
dialog.findViewById(R.id.pOption3).setOnClickListener(v -> {
event.invokeObserver(Collections.singletonList(data.get(0)), enums.etype.copy_link);
dialog.dismiss();
});
2020-01-24 16:23:31 +01:00
}
private void startingOrbotInfo()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_starting_orbot_info, Gravity.BOTTOM, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
2020-01-24 16:23:31 +01:00
}
2020-02-28 19:10:00 +01:00
private void sendBridgeMail()
{
2020-11-27 12:40:46 +01:00
initializeDialog(R.layout.popup_bridge_mail, Gravity.CENTER, FLAG_DIM_BEHIND);
2020-10-20 16:55:08 +02:00
dialog.findViewById(R.id.pDismiss).setOnClickListener(v -> dialog.dismiss());
dialog.findViewById(R.id.pNext).setOnClickListener(v -> {
dialog.dismiss();
final Handler handler = new Handler();
Runnable runnable = () -> {
try{
helperMethod.sendBridgeEmail(app_context);
}
catch (Exception ex){
2020-10-22 10:36:44 +02:00
createMessage(app_context,Collections.singletonList(app_context.getString(R.string.ALERT_NOT_SUPPORTED_MESSAGE)),enums.etype.on_not_support);
2020-10-20 16:55:08 +02:00
}
};
handler.postDelayed(runnable, 1000);
});
2020-01-24 16:23:31 +01:00
}
void onReset(){
2020-10-20 16:55:08 +02:00
if(dialog!=null){
dialog.dismiss();
2020-01-24 16:23:31 +01:00
}
}
/*External Helper Methods*/
2020-11-27 12:40:46 +01:00
void createMessage(AppCompatActivity app_context, List<Object> data, enums.etype type)
2020-01-24 16:23:31 +01:00
{
this.app_context = app_context;
this.data = data;
2020-10-20 16:55:08 +02:00
switch (type)
{
case welcome:
welcomeMessage();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case abi_error:
abiError();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case rate_failure:
rateFailure();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case reported_success:
reportedSuccessfully();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case bookmark:
bookmark();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case clear_history:
clearHistory();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case clear_bookmark:
clearBookmark();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case report_url:
reportURL();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case rate_app:
rateApp();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case download_file:
downloadFile();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case start_orbot:
startingOrbotInfo();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case download_file_long_press:
downloadFileLongPress();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case on_long_press_url:
openURLLongPress();
break;
2020-02-28 19:10:00 +01:00
2020-10-20 16:55:08 +02:00
case on_long_press_with_link:
popupDownloadFull();
2020-11-11 13:11:13 +01:00
break;
2020-02-28 19:10:00 +01:00
2020-10-20 16:55:08 +02:00
case on_bridge_mail:
sendBridgeMail();
break;
2020-01-24 16:23:31 +01:00
2020-10-20 16:55:08 +02:00
case on_not_support:
notSupportMessage();
break;
2020-11-11 13:11:13 +01:00
case data_cleared:
dataClearedSuccessfully();
break;
2020-01-24 16:23:31 +01:00
}
}
}