Skip to content

Commit

Permalink
Mejora calidad del código según Codacy (II)
Browse files Browse the repository at this point in the history
Se eliminan los errores de tipo "Error Prone" , "Code Style" y
"Unused code" según informe de Codacy.
  • Loading branch information
Ale Feltes committed Dec 5, 2017
1 parent 12591da commit 129a7ff
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class HomeActivity extends FragmentActivity implements NavigationDrawerFr

private static final String LOG_TAG = HomeActivity.class.getSimpleName();
private static final String TAG = FirebaseInstanceIdService.class.getSimpleName();
private NavigationDrawerFragment mNavigationDrawerFragment;

@Override
protected void onResume() {
Expand Down Expand Up @@ -182,6 +181,7 @@ private void doLogout(Intent intent) {
}

private void setupNavigationDrawerFragment() {
NavigationDrawerFragment mNavigationDrawerFragment;
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.menuFragment);
// It might happen while rotating that ?¿...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import io.github.jokoframework.BuildConfig;
import io.github.jokoframework.R;
import io.github.jokoframework.eula.Eula;
import io.github.jokoframework.login.Authenticable;
import io.github.jokoframework.login.CredentialsTextView;
import io.github.jokoframework.login.ParseLogin;
import io.github.jokoframework.mboehaolib.constants.Constants;
import io.github.jokoframework.mboehaolib.util.SecurityUtils;
import io.github.jokoframework.mboehaolib.util.Utils;
Expand All @@ -53,7 +55,6 @@ public class LoginActivity extends BaseActivity implements ProcessError {

private String LOG_TAG = LoginActivity.class.getSimpleName();
private CallbackManager callbackManager = CallbackManager.Factory.create();
private ProfileTracker mProfileTracker;
private AccessTokenTracker accessTokenTracker;
private AccessToken accessToken;
private Profile currentUser;
Expand Down Expand Up @@ -148,6 +149,7 @@ public void run() {
private class FacebookCallbackLogin implements FacebookCallback<LoginResult> {
@Override
public void onSuccess(LoginResult loginResult) {
ProfileTracker mProfileTracker;
//Mostramos el progress, hasta que vaya a la pantalla de transacciones
Log.d(LOG_TAG, "A mostrar process desde fb:onSuccess");
showProgress(true, "Login con Facebook...");
Expand Down Expand Up @@ -220,11 +222,13 @@ public void onClick(View view) {
showProgress(true, "Ingresando..."); // Muestra el progress bar mientras se obtine el acceso...

// -----LOGIN WITH PARSE--------------------------
/*Authenticable parseLogin = new ParseLogin(enterButton,progressView, mySelf,saveCredentials);
parseLogin.setPassword(password);
parseLogin.setUser(username);
parseLogin.saveCredentials();
parseLogin.authenticate();*/
if(Boolean.parseBoolean(getString(R.string.parse_enabled))) {
Authenticable parseLogin = new ParseLogin(enterButton, mySelf, saveCredentials);
parseLogin.setPassword(password);
parseLogin.setUser(username);
parseLogin.saveCredentials();
parseLogin.authenticate();
}

//// ------JWT LOGIN---------------------------------
saveCredentials(username, password);
Expand Down Expand Up @@ -323,8 +327,6 @@ private void makeLoginRequest(LoginRequest loginRequest, LoginRepository authApi


private void doLogin(LoginRequest loginRequest, LoginRepository authApi) {
long startTime = System.currentTimeMillis();
long endTime = 15 * 1000; // after 15 second, it ends and return and Error!...

UserData userData = getUserData();
authApi.login(loginRequest, Constants.CURRENT_MBOEHAO_VERSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = String.format("mboehao-v%s.db", DATABASE_VERSION);
protected Context context;
private static final String SQL_DELETE_ENTRIES;
private static SQLiteHelper _instance;

public final String CREATE_TABLE_ACTIVITY = "CREATE TABLE " + DaybookEntry.TABLE_NAME + "(" +
DaybookEntry.COLUMN_NAME_DAYBOOK_ID + " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n" +
DaybookEntry.COLUMN_NAME_AVERAGE_SECONDS + " type TEXT NOT NULL, \n" +
Expand All @@ -65,6 +63,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
UsageStatEntry.COLUMN_NAME_LAST_TIMESTAMP + " type TEXT NOT NULL, \n" +
UsageStatEntry.COLUMN_NAME_TOTAL_TIME_FOREGROUND + " type TEXT NOT NULL \n" +
"); \n";
protected Context context;

static {
StringBuilder builder = new StringBuilder();
Expand Down
14 changes: 3 additions & 11 deletions app/src/main/java/io/github/jokoframework/eula/Eula.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.view.View;
import android.webkit.WebView;
import android.widget.CheckBox;

import io.github.jokoframework.mboehaolib.constants.Constants;import io.github.jokoframework.dialog.SecurityDialog;
import io.github.jokoframework.mboehaolib.util.ImageUtils;
import io.github.jokoframework.R;
import io.github.jokoframework.dialog.SecurityDialog;
import io.github.jokoframework.mboehaolib.util.ImageUtils;

/**
* Created by joaquin on 04/09/17.
*/

public class Eula {
private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted";
private static final String PREFERENCES_EULA = "eula";
Expand Down Expand Up @@ -50,13 +48,12 @@ public static boolean show(final Activity activity) {
+ "</p> "
+ "</body></html>";
mWebView.loadData(eulaBodyText, "text/html; charset=utf-8", "utf-8");

View acceptButton = eulaView.findViewById(R.id.eula_accept_btn);
View refusetButton = eulaView.findViewById(R.id.eula_refuse_btn);
final CheckBox checkBox = (CheckBox) eulaView.findViewById(R.id.checkBoxAcceptEula);
dialogBuilder.setView(eulaView);
final AlertDialog alert = dialogBuilder.create();
//TODO:se puede agregar que el check se pueda habilitar solo cuando se termina de leer el EULA...
acceptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -77,11 +74,6 @@ public void onClick(View view) {
return true;
}

@NonNull
private static String getHtmlScaledFontSize() {
return Constants.HTML_SCALED_FONT_SIZE;
}

private static void acceptClicked(CheckBox checkBox, SharedPreferences preferences, AlertDialog alert, Activity activity) {
if (checkBox.isChecked()) {
accept(preferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

Expand Down Expand Up @@ -52,9 +51,7 @@ public class NavigationDrawerFragment extends Fragment {
private static final long MENU_ID_IMAGE2 = 2L;
private static final long MENU_ID_IMAGE3 = 3L;
private static final long MENU_ID_LOGOUT = 4L;
private static final long MENU_ID_OPTIONS = 5L;
private static final long MENU_ID_HELP = 6L;
private static final long MENU_ID_PREFERENCES = 7L;
private static final long MENU_ID_CHANGEPASS = 8L;

/**
Expand All @@ -69,7 +66,6 @@ public class NavigationDrawerFragment extends Fragment {
private DrawerLayout mDrawerLayout;
private ListView mDrawerListView;
private View mFragmentContainerView;
private ImageView imageHeader;
public View header;
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Button getLoginButton() {
return loginButton;
}

public ParseLogin(Button loginButton, View progressBar, Activity activity, CheckBox saveCredentials) {
public ParseLogin(Button loginButton, Activity activity, CheckBox saveCredentials) {
this.loginButton = loginButton;
this.progressBar = progressBar;
this.activity = activity;
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/io/github/jokoframework/pojo/Event.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.github.jokoframework.pojo;

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;

/**
* Created by joaquin on 23/08/17.
*
* @author joaquin
* @author afeltes
*/

public class Event implements Serializable {

private static final long serialVersionUID = 1L;
Expand All @@ -14,11 +18,11 @@ public class Event implements Serializable {
private String description;
private Integer resourceIconId;
private Integer iconMenu;
private Class activity;

public Event(Long id) {
this.id = id;
}
private Class activity;

public Class getActivity() {
return activity;
Expand Down Expand Up @@ -64,13 +68,15 @@ public void setResourceIconId(Integer resourceIconId) {
this.resourceIconId = resourceIconId;
}


@Override
public String toString() {
return "Event{" +
"id=" + id +
", description='" + description + '\'' +
", resourceIconId=" + resourceIconId +
", iconMenu=" + iconMenu +
'}';
return new ToStringBuilder(this)
.append("id", id)
.append("description", description)
.append("resourceIconId", resourceIconId)
.append("iconMenu", iconMenu)
.append("activity", activity)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public <R> Observable<?> adapt(Call<R> call) {
@Override
public Observable call(final Throwable throwable) {
if (throwable instanceof SocketTimeoutException || throwable instanceof UnknownHostException
|| throwable instanceof retrofit2.adapter.rxjava.HttpException
|| throwable instanceof HttpException
|| throwable instanceof ConnectException) {
Observable observableWithError = Observable.create(new Observable.OnSubscribe<Object>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,40 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import android.support.v4.app.NotificationCompat;

import io.github.jokoframework.R;
import com.parse.ParseUser;

import io.github.jokoframework.R;
import io.github.jokoframework.activity.HomeActivity;
import io.github.jokoframework.activity.LoginActivity;
import io.github.jokoframework.mboehaolib.constants.Constants;
import io.github.jokoframework.mboehaolib.util.Utils;

/**
* Created by joaquin on 03/10/17.
* @author joaquin
* @author afeltes
*/

public class TestServiceNotification extends PeriodicService {
public static final String LOG_TAG = TestServiceNotification.class.getSimpleName();

private static boolean alarmForSet;

public static boolean isAlarmForSet() {
return alarmForSet;
}

public static void setAlarmForSet(boolean alarmSet) {
alarmForSet = alarmSet;
}

private Integer notificationIconId;

public Integer getNotificationIconId() {
return notificationIconId;
}

public void setNotificationIconId(Integer notificationIconId) {
this.notificationIconId = notificationIconId;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
notificationBuilder();
return START_NOT_STICKY;
}

protected void notificationBuilder(){
protected void notificationBuilder() {
setNotificationIconId(R.drawable.ic_mboehao);
String message;
message = getString(R.string.notification_message);
Intent dailyIntent;
if(ParseUser.getCurrentUser() != null){
if (ParseUser.getCurrentUser() != null) {
dailyIntent = new Intent(this, HomeActivity.class);
}else{
} else {
dailyIntent = new Intent(this, LoginActivity.class);
}
dailyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Expand Down Expand Up @@ -83,21 +65,40 @@ protected void notificationBuilder(){
}

public static void setAlarm(Context context) {
setAlarmForSet(Utils.getBooleanPrefs(context,Constants.PREFERENCE_ATTRIBUTE_NOTIFICATION_CHECKED));
setAlarmForSet(Utils.getBooleanPrefs(context, Constants.PREFERENCE_ATTRIBUTE_NOTIFICATION_CHECKED));
if (context != null) {
ParseUser user = ParseUser.getCurrentUser();
if (user != null) {
setServiceClass(TestServiceNotification.class);
if(isAlarmForSet()){
PeriodicService.setAlarm(context,0,1,0,Constants.ONE_DAY,getServiceClass());
}else{
if (isAlarmForSet()) {
PeriodicService.setAlarm(context, 0, 1, 0, Constants.ONE_DAY, getServiceClass());
} else {
cancelAlarm(context);
}
}
}
}

public static void cancelAlarm(Context context){
PeriodicService.cancelAlarm(context,TestServiceNotification.class);
public static void cancelAlarm(Context context) {
PeriodicService.cancelAlarm(context, TestServiceNotification.class);
}

public static boolean isAlarmForSet() {
return alarmForSet;
}

public static void setAlarmForSet(boolean alarmSet) {
alarmForSet = alarmSet;
}


public Integer getNotificationIconId() {
return notificationIconId;
}

public void setNotificationIconId(Integer notificationIconId) {
this.notificationIconId = notificationIconId;
}


}
Loading

0 comments on commit 129a7ff

Please sign in to comment.