Skip to content

Commit

Permalink
redesigned auth fragmnent
Browse files Browse the repository at this point in the history
  • Loading branch information
iMaks99 committed May 15, 2019
1 parent 7d112e5 commit c03d7cb
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;

public class AuthenticationActivity extends AppCompatActivity {

private SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -17,11 +21,20 @@ protected void onCreate(Bundle savedInstanceState) {
if (actionBar != null)
actionBar.hide();

sharedPreferences = getSharedPreferences("AuthPref", Context.MODE_PRIVATE);
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

fragmentManager.beginTransaction()
.replace(R.id.auth_content_frame, new DBConnectionFragment(), "DBConnectionFragment")
.commit();
if (!sharedPreferences.getBoolean("is_db_connected", false))
fragmentManager.beginTransaction()
.replace(R.id.auth_content_frame, new DBConnectionFragment(), "DBConnectionFragment")
.addToBackStack(null)
.commit();
else
fragmentManager.beginTransaction()
.replace(R.id.auth_content_frame, new LoginFragment())
.addToBackStack(null)
.commit();

}
}
46 changes: 41 additions & 5 deletions app/src/main/java/com/example/maks/odooprojects/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.maks.odooprojects.models.ResPartner;
import com.example.maks.odooprojects.network.IGetDataService;
import com.example.maks.odooprojects.network.RetrofitClientInstance;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand All @@ -25,6 +27,8 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import org.w3c.dom.Text;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
Expand All @@ -39,6 +43,8 @@ public class MainActivity extends AppCompatActivity implements
NavigationView navigationView;
Toolbar toolbar;
Drawable toolbarDrawable;
SharedPreferences sharedPreferences;
IGetDataService service;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -49,9 +55,10 @@ protected void onCreate(Bundle savedInstanceState) {

void init() {

SharedPreferences sharedPreferences = getSharedPreferences("AuthPref", Context.MODE_PRIVATE);
sharedPreferences = getSharedPreferences("AuthPref", Context.MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
Boolean isConnected = sharedPreferences.getBoolean("is_db_connected", false);
service = RetrofitClientInstance.getRetrofitInstance().create(IGetDataService.class);

if (token.isEmpty()) {

Expand All @@ -65,8 +72,6 @@ void init() {
progressDialog.setMessage("Connecting to server...");
progressDialog.show();

IGetDataService service = RetrofitClientInstance.getRetrofitInstance().create(IGetDataService.class);

Call<ResponseBody> result = service.connectToDb(
sharedPreferences.getString("db_name", ""),
sharedPreferences.getString("db_host", ""),
Expand Down Expand Up @@ -125,12 +130,36 @@ void goToMainPage() {
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

Call<ResPartner> request = service.getUser(
sharedPreferences.getString("token", ""),
sharedPreferences.getString("db_name", "")
);

request.enqueue(new Callback<ResPartner>() {
@Override
public void onResponse(Call<ResPartner> call, Response<ResPartner> response) {
if (response.isSuccessful()) {
ResPartner user = response.body();
View headerView = navigationView.getHeaderView(0);
TextView userName = headerView.findViewById(R.id.nav_user_name);
userName.setText(user.getName());
TextView userMail = headerView.findViewById(R.id.nav_user_mail);
userMail.setText(user.getEmail());
}
}

@Override
public void onFailure(Call<ResPartner> call, Throwable t) {

}
});

showSelectedFragment(new ProjectsRecyclerViewFragment());
}

public void crateMenuButton(){
public void crateMenuButton() {
toggle.setDrawerIndicatorEnabled(true);
if(toolbarDrawable == null) {
if (toolbarDrawable == null) {
toolbarDrawable = toolbar.getNavigationIcon();
}
toolbar.setNavigationIcon(toolbarDrawable);
Expand Down Expand Up @@ -173,6 +202,12 @@ public boolean onNavigationItemSelected(MenuItem item) {
case R.id.nav_departments:
fragment = new DepartmentsRecyclerViewFragment();
break;

case R.id.nav_logout:
sharedPreferences.edit().putString("token", "").apply();
Intent intent = new Intent(this, AuthenticationActivity.class);
startActivity(intent);
finish();
}

showSelectedFragment(fragment);
Expand All @@ -184,6 +219,7 @@ private void showSelectedFragment(Fragment fragment) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, fragment)
.addToBackStack(null)
.commit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.example.maks.odooprojects.models.ProjectTaskType;
import com.example.maks.odooprojects.models.ResPartner;

import java.lang.reflect.GenericArrayType;
import java.util.Calendar;
import java.util.List;

Expand All @@ -31,6 +32,12 @@ Call<List<ProjectProject>> getAllProjects(
@Header("dbname") String dbname
);

@GET("getuser/")
Call<ResPartner> getUser(
@Header("Authorization") String token,
@Header("dbname") String dbname
);

@GET("getprojectbyid/")
Call<ProjectProject> getProjectById(
@Header("Authorization") String token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class RetrofitClientInstance {

private static Retrofit retrofit;
private static final String BASE_URL = "http://192.168.42.38:9595/";
private static final String BASE_URL = "http://192.168.42.238:9595/";

public static Retrofit getRetrofitInstance(){
if (retrofit == null){
Expand Down
Binary file added app/src/main/res/drawable-v24/projects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_logout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M510.371,226.513c-1.088,-2.603 -2.645,-4.971 -4.629,-6.955l-63.979,-63.979c-8.341,-8.32 -21.824,-8.32 -30.165,0c-8.341,8.341 -8.341,21.845 0,30.165l27.584,27.584H320.013c-11.797,0 -21.333,9.557 -21.333,21.333s9.536,21.333 21.333,21.333h119.168l-27.584,27.584c-8.341,8.341 -8.341,21.845 0,30.165c4.16,4.181 9.621,6.251 15.083,6.251s10.923,-2.069 15.083,-6.251l63.979,-63.979c1.984,-1.963 3.541,-4.331 4.629,-6.955C512.525,237.606 512.525,231.718 510.371,226.513z"/>
<path android:fillColor="#FF000000" android:pathData="M362.68,298.667c-11.797,0 -21.333,9.557 -21.333,21.333v106.667h-85.333V85.333c0,-9.408 -6.187,-17.728 -15.211,-20.437l-74.091,-22.229h174.635v106.667c0,11.776 9.536,21.333 21.333,21.333s21.333,-9.557 21.333,-21.333v-128C384.013,9.557 374.477,0 362.68,0H21.347c-0.768,0 -1.451,0.32 -2.197,0.405c-1.003,0.107 -1.92,0.277 -2.88,0.512c-2.24,0.576 -4.267,1.451 -6.165,2.645c-0.469,0.299 -1.045,0.32 -1.493,0.661C8.44,4.352 8.376,4.587 8.205,4.715C5.88,6.549 3.939,8.789 2.531,11.456c-0.299,0.576 -0.363,1.195 -0.597,1.792c-0.683,1.621 -1.429,3.2 -1.685,4.992c-0.107,0.64 0.085,1.237 0.064,1.856c-0.021,0.427 -0.299,0.811 -0.299,1.237V448c0,10.176 7.189,18.923 17.152,20.907l213.333,42.667c1.387,0.299 2.795,0.427 4.181,0.427c4.885,0 9.685,-1.685 13.525,-4.843c4.928,-4.053 7.808,-10.091 7.808,-16.491v-21.333H362.68c11.797,0 21.333,-9.557 21.333,-21.333V320C384.013,308.224 374.477,298.667 362.68,298.667z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_outline_assignment_ind_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M19,3h-4.18C14.4,1.84 13.3,1 12,1s-2.4,0.84 -2.82,2L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM12,2.75c0.22,0 0.41,0.1 0.55,0.25 0.12,0.13 0.2,0.31 0.2,0.5 0,0.41 -0.34,0.75 -0.75,0.75s-0.75,-0.34 -0.75,-0.75c0,-0.19 0.08,-0.37 0.2,-0.5 0.14,-0.15 0.33,-0.25 0.55,-0.25zM19,19L5,19L5,5h14v14zM12,6c-1.65,0 -3,1.35 -3,3s1.35,3 3,3 3,-1.35 3,-3 -1.35,-3 -3,-3zM12,10c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM6,16.47L6,18h12v-1.53c0,-2.5 -3.97,-3.58 -6,-3.58s-6,1.07 -6,3.58zM8.31,16c0.69,-0.56 2.38,-1.12 3.69,-1.12s3.01,0.56 3.69,1.12L8.31,16z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_outline_business_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,7L12,3L2,3v18h20L22,7L12,7zM6,19L4,19v-2h2v2zM6,15L4,15v-2h2v2zM6,11L4,11L4,9h2v2zM6,7L4,7L4,5h2v2zM10,19L8,19v-2h2v2zM10,15L8,15v-2h2v2zM10,11L8,11L8,9h2v2zM10,7L8,7L8,5h2v2zM20,19h-8v-2h2v-2h-2v-2h2v-2h-2L12,9h8v10zM18,11h-2v2h2v-2zM18,15h-2v2h2v-2z"/>
</vector>
112 changes: 97 additions & 15 deletions app/src/main/res/layout/fragment_db_connection.xml
Original file line number Diff line number Diff line change
@@ -1,77 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DBConnectionFragment"
android:orientation="vertical">
tools:context=".DBConnectionFragment">

<TextView
android:id="@+id/textView12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="database name" />
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:text="database name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView8" />

<EditText
android:id="@+id/db_name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAutofill="yes"
android:text="coursework"/>
android:text="coursework"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="database host" />
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:text="database host"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/db_name_et" />

<EditText
android:id="@+id/db_host_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAutofill="yes"
android:text="localhost"/>
android:text="localhost"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="database port" />
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:text="database port"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/db_host_et" />

<EditText
android:id="@+id/db_port_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAutofill="yes"
android:inputType="numberDecimal"
android:text="5432"
android:inputType="numberDecimal"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5" />

<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="database user" />
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:text="database user"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/db_port_et" />

<EditText
android:id="@+id/db_user_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAutofill="yes"
android:text="openpg"/>
android:text="openpg"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8" />

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="database password" />
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:text="database password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/db_user_et" />

<EditText
android:id="@+id/db_password_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAutofill="yes"
android:inputType="textPassword"
android:text="openpgpwd"
android:inputType="textPassword"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<Button
android:id="@+id/connect_to_db"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Connect"/>
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:text="Connect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent" />

</LinearLayout>
<ImageView
android:id="@+id/imageView8"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:src="@drawable/projects"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit c03d7cb

Please sign in to comment.