Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
errores varios corregidos
Browse files Browse the repository at this point in the history
  • Loading branch information
esalessandrxx committed Oct 5, 2023
1 parent 6343a92 commit eeef448
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 109 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.arr.simple"
minSdk = 23
targetSdk = 33
versionCode = 40
versionName = "4.0.0"
versionCode = 41
versionName = "4.0.1"

vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -69,7 +69,6 @@ dependencies {
implementation("com.github.applifycu:nautaclear:1.0.0")
implementation("com.github.applifycu:didi-library:1.0.2-alpha3")

implementation("com.github.Drjacky:ImagePicker:2.3.22")
implementation("de.hdodenhof:circleimageview:3.1.0")
implementation(project(":preference"))
implementation(project(":fingerprint"))
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme">

<receiver
android:name=".widget.BalancesWidget"
android:name=".widget.WidgetBalances"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/arr/simple/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ protected void onCreate(Bundle savedInstanceState) {
navController.navigate(id, null);
}
if (id == R.id.nav_telepuntos) {
openGoogleMap();
// startActivity(new Intent(this, Test.class));
openGoogleMap();
// startActivity(new Intent(this, Test.class));
}
if (id == R.id.nav_settings) {
navController.navigate(id, null);
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/com/arr/simple/broadcast/BalancesBroadcast.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.RemoteViews;

import androidx.annotation.RequiresApi;
Expand Down Expand Up @@ -53,16 +54,22 @@ public void onReceive(Context context, Intent intent) {
response = new ResponseUssd(ussd);
Handler handler = new Handler(Looper.getMainLooper());
executeUssdRequest(context, intent, handler, 0);

handler.postDelayed(()->{
updateWidget(context, intent);
}, 5000);

// TODO: SharedPreferences
spBalance = PreferenceManager.getDefaultSharedPreferences(context);
editor = spBalance.edit();
SIM = spBalance.getString("sim", "0");
}

private void updateWidget(Context mContext, Intent mIntent) {
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(
() -> {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
int[] appWidgetIds = mIntent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
int[] appWidgetIds = mIntent.getIntArrayExtra(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetIds != null) {
for (int appWidgetId : appWidgetIds) {
// Actualizar la vista del saldo del paquete
Expand All @@ -74,18 +81,24 @@ private void updateWidget(Context mContext, Intent mIntent) {
views.setTextViewText(R.id.appwidget_text_vence, response.getVenceData());
views.setTextViewText(R.id.appwidget_text_minutos, response.getMinutos());
views.setTextViewText(R.id.appwidget_text_sms, response.getMensajes());
views.setTextViewText(R.id.time_update,spBalance.getString("actualizado", "sin actualizar").replace("Actualizado: ", "").toString());

// actualizado
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
String time = sp.getString("actualizado", "sin actualizar").replace("Actualizado:\n", "");
views.setTextViewText(R.id.time_update, time);

appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
});
}

private void executeUssdRequest(Context context, Intent intent, Handler handler, int index) {
if (index >= ussdCodes.length) {
// update widget
updateWidget(context, intent);
// actualizar tiempo
updateTime(context);

updateWidget(context, intent);

// mostrar u ocultar notificación de balances actualizados
boolean isShow = spBalance.getBoolean("not_update_balances", false);
if (isShow) {
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/arr/simple/log/CrashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class CrashActivity extends AppCompatActivity {

private ActivityCrashBinding binding;
private BugSend bugSend;

private boolean delete = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -32,10 +33,14 @@ protected void onCreate(Bundle savedInstanceState) {
// bug send
bugSend = new BugSend(this);
binding.logText.setText(versionName + "\n" + bugSend.readError());

binding.closeButton.setOnClickListener(view->{
System.exit(0);
bugSend.deleteStackTrace();
if(delete) {
bugSend.deleteStackTrace();
System.exit(0);
}else{
delete = true;
}
});

binding.reportButton.setOnClickListener(view->{
Expand Down
90 changes: 0 additions & 90 deletions app/src/main/java/com/arr/simple/widget/BalancesWidget.java

This file was deleted.

104 changes: 104 additions & 0 deletions app/src/main/java/com/arr/simple/widget/WidgetBalances.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.arr.simple.widget;
import android.Manifest;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.widget.RemoteViews;
import android.widget.Toast;

import androidx.core.content.ContextCompat;

import androidx.preference.PreferenceManager;
import com.arr.simple.R;
import com.arr.simple.broadcast.BalancesBroadcast;
import com.arr.ussd.ResponseUssd;
import com.arr.ussd.utils.UssdUtils;

public class WidgetBalances extends AppWidgetProvider {

private RemoteViews views;
private PendingIntent pending;
private ResponseUssd response;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for(int appWidgetId : appWidgetIds) {

// utils
UssdUtils utils = new UssdUtils(context);
response = new ResponseUssd(utils);

/* comprobar si la version de Android es superior a android 8 para mostrar el Widget
* de lo contrario se muestra una vista informando que el dispositivo no es compatible
* con la función.
*/
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O){
views = new RemoteViews(context.getPackageName(), R.layout.balances_widget);

/* comprobar si el usuario dio permisos de LLAMADA a la aplicación */
int permissions = ContextCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE);
if(permissions != PackageManager.PERMISSION_GRANTED){

/* Llevar al usuario a los ajustes de la aplicacion para que conceda el permiso de LLAMADAS */
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
pending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.appwidget_sync, pending);

}else{

/* si el permiso esta dado permitir al usuario sincronizar los balances */
Intent intent = new Intent(context, BalancesBroadcast.class);
pending = PendingIntent.getBroadcast(context, 0, intent , PendingIntent.FLAG_IMMUTABLE);
views.setOnClickPendingIntent(R.id.appwidget_sync, pending);
}

/* mostrar contenido en los TextView */
Handler handler = new Handler(Looper.getMainLooper());
Runnable runnable = new Runnable(){
@Override
public void run() {
views.setTextViewText(R.id.appwidget_text_minutos, response.getMinutos());
views.setTextViewText(R.id.appwidget_text_sms, response.getMensajes());
views.setTextViewText(R.id.appwidget_text_paquete, response.getDataAll());
views.setTextViewText(R.id.appwidget_text_lte, response.getLTE().replace(" LTE",""));
views.setTextViewText(R.id.appwidget_text_vence, response.getVenceData());

// actualizado
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String time = sp.getString("actualizado", "sin actualizar").replace("Actualizado:\n", "");
views.setTextViewText(R.id.time_update, time);

//update to 5 seconds
handler.postDelayed(this, 5000);
}
};
handler.post(runnable);


/* actualizar vista del widget */
appWidgetManager.updateAppWidget(appWidgetId, views);
}else{
views = new RemoteViews(context.getPackageName(), R.layout.layout_widget_not_compatible);
appWidgetManager.updateAppWidget(appWidgetId, views);
}

}

}

@Override
public void onEnabled(Context context) {
super.onEnabled(context);
Toast.makeText(context, "¡Antes de agregar el widget conceda el permiso de llamada!", Toast.LENGTH_LONG).show();
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<string name="title_preference_apariencia">Apariencia</string>
<string name="summary_preference_apariencia">Ajustes de la ui, temas, actualizaciones de la aplicación</string>
<string name="title_preference_theme">Tema</string>
<string name="theme_system">Según el Sistema</string>
<string name="theme_system">Según el sistema</string>
<string name="theme_light">Claro</string>
<string name="theme_dark">Oscuro</string>
<string name="title_preference_home">Inicio</string>
Expand Down

0 comments on commit eeef448

Please sign in to comment.