Commit 0fe0899a authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Merge branch 'account_edit' into 'develop'

Account edit

See merge request !9
parents 43f75bce 3bdea922
......@@ -3,8 +3,10 @@
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea/*
/.idea/misc.xml
.DS_Store
/build
/captures
.externalNativeBuild
build.gradle
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Mobile.iml" filepath="$PROJECT_DIR$/Mobile.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -3,13 +3,18 @@
package="br.ufpr.c3sl.agendador.agendador">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
......@@ -33,6 +38,12 @@
<activity android:name=".SignupActivity">
</activity>
<activity android:name=".AccountActivity">
</activity>
<activity android:name=".ForgotPasswordActivity">
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -11,6 +11,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.presenters.CepPresenter;
import br.ufpr.c3sl.agendador.agendador.views.CepView;
......@@ -24,6 +25,7 @@ public class CepActivity extends AppCompatActivity implements CepView {
private EditText et_cep;
private TextView tv_invalid_cep;
private ProgressBar pb_waiting;
private ConnectionErrorDialog dg_connection;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -87,8 +89,13 @@ public class CepActivity extends AppCompatActivity implements CepView {
}
@Override
public void setNoConnection(boolean enable) {
public void setNoConnection(boolean enabled) {
if(enabled){
if(dg_connection == null){
dg_connection = new ConnectionErrorDialog();
}
dg_connection.show(getFragmentManager(), "noConnectionDialog");
}
}
@Override
......
package br.ufpr.c3sl.agendador.agendador;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.presenters.ForgotPasswordPresenter;
import br.ufpr.c3sl.agendador.agendador.views.ForgotPasswordView;
/**
* Created by Horstmann on 23/02/17.
*/
public class ForgotPasswordActivity extends AppCompatActivity implements ForgotPasswordView {
private ForgotPasswordPresenter presenter;
private Button btn_send;
private EditText et_cpf;
private TextView tv_cpf, tv_cpf_warning;
private ProgressBar pb_waiting;
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
presenter = new ForgotPasswordPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}
setContentView(R.layout.activity_login);
tv_cpf = (TextView) findViewById(R.id.tv_forgot_password_cpf);
tv_cpf_warning = (TextView) findViewById(R.id.tv_forgot_password_invalid_cpf);
}
@Override
public void setProgressBar(boolean enabled) {
}
}
package br.ufpr.c3sl.agendador.agendador;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
......@@ -7,6 +14,8 @@ import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.view.menu.MenuBuilder.Callback;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
......@@ -19,6 +28,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.presenters.HomePresenter;
import br.ufpr.c3sl.agendador.agendador.views.HomeView;
......@@ -31,12 +41,20 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
private HomePresenter presenter;
private ObscuredSharedPreferences osb;
private MenuBuilder menuBuilder;
private ActionMenuView actionMenuView;
private ImageView drawerHamburger;
private ImageView drawerHamburger, drawerProfilePicture;
private DrawerLayout drawer;
private NavigationView navigationView;
private TextView drawerCitizenName, drawerCityName, homeCitizenWelcome, tv_presentation;
private UserPhotoHelper userPhotoHelper;
private String citizenName, citizenCity;
private ConfirmationDialog confirmationDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -52,36 +70,71 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", this.MODE_PRIVATE);
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
citizenName = osb.getString("name", null);
citizenCity = osb.getString("city.name", null);
actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
//noinspection RestrictedApi
menuBuilder.setCallback(new Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
return onOptionsItemSelected(item);
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
}
});
confirmationDialog = new ConfirmationDialog();
drawerHamburger = (ImageView) toolbar.findViewById(R.id.img_toolbar_hamburger);
homeCitizenWelcome = (TextView) findViewById(R.id.tv_homeact_welcome);
homeCitizenWelcome.setText(String.format(getString(R.string.welcome), citizenName));
tv_presentation = (TextView) findViewById(R.id.tv_homeact_presentation_more);
tv_presentation = (TextView) findViewById(R.id.tv_homeact_moreinfo);
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.home_navigation_view);
View headerView = navigationView.getHeaderView(0);
drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
userPhotoHelper = new UserPhotoHelper(getBaseContext());
drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
drawerCityName = (TextView) headerView.findViewById(R.id.tv_drawerheader_city_name);
drawerCitizenName.setText(citizenName);
drawerCityName.setText(citizenCity);
if(userPhotoHelper.existsPhoto()){
userPhotoHelper.updateImgView(drawerProfilePicture, userPhotoHelper.getPhotoFileUri());
}
drawerHamburger.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer(Gravity.LEFT);
drawerCitizenName = (TextView) drawer
.findViewById(R.id.tv_drawerheader_citizen_name);
drawerCityName = (TextView) drawer.findViewById(R.id.tv_drawerheader_city_name);
drawerCitizenName.setText(citizenName);
drawerCityName.setText(citizenCity);
}
});
//Changing text style
SpannableString text = new SpannableString(getString(R.string.schedules_more_information));
navigationView.setNavigationItemSelectedListener(this);
changeTextColor();
}
@TargetApi(23)
private void changeTextColor(){
//Changing text style
SpannableString text = new SpannableString(getString(R.string.schedules_more_information));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
text.setSpan(new ForegroundColorSpan(getColor(R.color.colorGreen)), 123, 143, 0);
......@@ -92,18 +145,15 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorGreen)), 88, 108, 0);
}
tv_presentation.setText(text, TextView.BufferType.SPANNABLE);
NavigationView navigationView = (NavigationView) findViewById(R.id.home_navigation_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
MenuItem item = navigationView.getMenu().findItem(R.id.nav_my_info);
item.setChecked(false);
}
@Override
......@@ -130,12 +180,59 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, actionMenuView.getMenu());
getMenuInflater().inflate(R.menu.main_menu, menuBuilder);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logout_actionbtn:
confirmationDialog.show(getFragmentManager(), "Confirm");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.nav_my_info:
item.setChecked(false);
intent = new Intent(this, AccountActivity.class);
startActivity(intent);
return true;
default:
}
return false;
}
}
\ No newline at end of file
public static class ConfirmationDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.signout_confirmation)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
HomeActivity activity = (HomeActivity) getActivity();
activity.presenter.onSignOutClicked();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
}
package br.ufpr.c3sl.agendador.agendador;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
......@@ -10,15 +10,20 @@ import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.presenters.LoginPresenter;
import br.ufpr.c3sl.agendador.agendador.views.LoginView;
......@@ -32,8 +37,12 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
private Button btn_login;
private EditText et_cpf, et_password;
private TextView tv_signup, tv_forgot_password, tv_description;
private ProgressBar pb_waiting;
private ConnectionErrorDialog dg_connection_error;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -64,7 +73,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
tv_forgot_password.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: add startactivity to "forgot password" screen
presenter.onForgotPasswordClicked();
}
});
......@@ -77,8 +86,27 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.onLoginClicked(Mask.unmask(et_cpf.getText().toString()),
et_password.getText().toString());
TextView textView = (TextView) findViewById(R.id.tv_loginact_error);
if(et_cpf.getText().toString().isEmpty() || et_password.getText().toString().isEmpty()){
textView.setText(R.string.loginact_empty);
textView.setTextColor(ResourcesCompat.getColor(getResources(),
R.color.colorRed, null));
}
else {
if (ConnectionChecker.hasConnection(getBaseContext()))
presenter.onLoginClicked(Mask.unmask(et_cpf.getText().toString()),
et_password.getText().toString());
else {
if (dg_connection_error == null)
dg_connection_error = new ConnectionErrorDialog();
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_no_connection_message));
dg_connection_error.setArguments(bundle);
dg_connection_error.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
setWrongPassword(false);
}
}
}
});
......@@ -153,7 +181,15 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
@Override
public void setNoConnection(boolean enabled) {
// TODO: show an error (no connection)
if(enabled){
Bundle bundle = new Bundle();
if(dg_connection_error == null){
dg_connection_error = new ConnectionErrorDialog();
}
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_connection_error_message));
dg_connection_error.setArguments(bundle);
dg_connection_error.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
@Override
......@@ -163,6 +199,19 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
finish();
}
@Override
public void afterSuccessfulPhoto(Bitmap bitmap, String uid){
// TODO: 17/04/17 user messages & error warning
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext(), uid);
try {
userPhotoHelper.saveBitmap(bitmap);
} catch (IOException e) {
Toast.makeText(this, "Ocorreu um problema ao atualizar sua foto de perfil", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
afterSuccessfulLogin();
}
private class LoginChangeListener implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
......
......@@ -20,6 +20,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
}
setContentView(R.layout.activity_main);
onLoaded();
}
@Override
......
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.content.Context;
import android.net.ConnectivityManager;
/**
* Created by Lucas Braz Cunha on 21/03/17.
*/
public class ConnectionChecker {
/*
This method does not check for "real" internet conection,
it only checks if the device is connected to a network.
*/
public static boolean hasConnection(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null &&
cm.getActiveNetworkInfo().isConnectedOrConnecting();
}
}
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import br.ufpr.c3sl.agendador.agendador.R;
/**
* Created by Lucas Braz Cunha on 20/03/17.
*/
public class ConnectionErrorDialog extends DialogFragment {
public static final String DIALOG_CONNECTION_ERROR = "connection_error";
public static final String DIALOG_MESSAGE_KEY = "message";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getArguments().getString(DIALOG_MESSAGE_KEY))
.setTitle(getString(R.string.warningDialog_title))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
}
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.R;
/**
* Created by Lucas B. Cunha on 29/03/17.
*/
public class CustomAdapter extends BaseAdapter {