Update UI board view
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Umberto Furno 2019-12-31 14:53:08 +01:00
parent baced120f9
commit 45fe2381ad
7 changed files with 344 additions and 33 deletions

View File

@ -17,11 +17,11 @@
<activity android:name=".DriverActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".view.BoardViewActivity" />
<activity android:name=".view.BoardViewActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".view.WListsListActivity"
android:label="WList"
android:theme="@style/AppTheme.NoActionBar"/>

View File

@ -1,45 +1,71 @@
package it.unisannio.ding.ids.wedroid.app.view;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Objects;
import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.wrapper.entity.Board;
import it.unisannio.ding.ids.wedroid.wrapper.entity.User;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class BoardViewActivity extends AppCompatActivity {
TextView boardTitle;
Button getLists;
String idBoard, username;
TextView description, members, permission, creationDate, lastModificationDate;
View divider1, divider2, divider3;
ListView listView;
Button getListsButton;
SharedPreferenceHelper sp;
ServicesFactory service;
Toolbar myToolbar;
Board board;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_board_view);
myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Intent i = getIntent();
final String idBoard= i.getStringExtra("idBoard");
boardTitle = findViewById(R.id.title_board);
getLists = findViewById(R.id.getLists);
idBoard= i.getStringExtra("idBoard");
getListsButton = findViewById(R.id.getLists);
description = findViewById(R.id.descriptionTxt);
members = findViewById(R.id.membersTxt);
permission = findViewById(R.id.permissionTxt);
creationDate = findViewById(R.id.createdDate);
lastModificationDate = findViewById(R.id.modifiedDate);
divider1 = findViewById(R.id.divider1);
divider2 = findViewById(R.id.divider2);
divider3= findViewById(R.id.divider3);
listView = findViewById(R.id.listViewID);
sp = new SharedPreferenceHelper(this);
sp.setBoardId(idBoard);
initializeUI(idBoard);
getLists.setOnClickListener(new View.OnClickListener() {
getListsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), WListsListActivity.class);
@ -53,13 +79,110 @@ public class BoardViewActivity extends AppCompatActivity {
service = new ServicesFactory(sp);
service.getBoardService().getBoard(idBoard).enqueue(new Callback<Board>() {
@Override
public void onResponse(Call<Board> call, Response<Board> response) {
boardTitle.setText(boardTitle.getText().toString() + response.body().getTitle());
public void onResponse(@NotNull Call<Board> call, @NotNull Response<Board> response) {
board = response.body();
Objects.requireNonNull(getSupportActionBar()).setTitle(board.getTitle());
myToolbar.setBackgroundColor(Color.parseColor(encodeColor(
board.getBackgroundColor().toString())));
Drawable background = getListsButton.getBackground();
background.setTint(Color.parseColor(encodeColor(
board.getBackgroundColor().toString())));
getListsButton.setBackgroundDrawable(background);
description.setText(board.getDescription());
permission.setText(board.getPermission().toString());
members.setText("");
for(int i =0; i<board.getMembers().size(); i++){
replaceIDUserToUsername(board.getMembers().get(i).getUserId());
}
creationDate.append("\n" + board.getCreatedAt());
lastModificationDate.append("\n" + board.getModifiedAt());
divider1.setBackgroundColor(Color.parseColor(encodeColor(
board.getBackgroundColor().toString())));
divider2.setBackgroundColor(Color.parseColor(encodeColor(
board.getBackgroundColor().toString())));
divider3.setBackgroundColor(Color.parseColor(encodeColor(
board.getBackgroundColor().toString())));
ArrayList<String> labelsTitle = new ArrayList<>();
for (int i=0; i<board.getLabels().size(); i++){
labelsTitle.add(board.getLabels().get(i).getName());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_list_item_1, labelsTitle);
listView.setAdapter(adapter);
}
@Override
public void onFailure(Call<Board> call, Throwable t) {
boardTitle.setText(t.toString());
//boardTitle.setText(t.toString());
//TODO
}
});
}
private String encodeColor(String color){
String encodedColor;
if(color.equalsIgnoreCase("belize")){
encodedColor="#2980B9";
}
else if(color.equalsIgnoreCase("nephritis")){
encodedColor="#27AE60";
}
else if(color.equalsIgnoreCase("pomegranate")){
encodedColor="#C0392B";
}
else if(color.equalsIgnoreCase("pumpkin")){
encodedColor="#E67E22";
}
else if(color.equalsIgnoreCase("wisteria")){
encodedColor="#8E44AD";
}
else if(color.equalsIgnoreCase("moderatepink")){
encodedColor="#CD5A91";
}
else if(color.equalsIgnoreCase("strongcyan")){
encodedColor="#00AECC";
}
else if(color.equalsIgnoreCase("dark")){
encodedColor="#2C3E51";
}
else if(color.equalsIgnoreCase("midnight")){
encodedColor="#2C3E50";
}
else if(color.equalsIgnoreCase("relax")){
encodedColor="#27AE61";
}
else if(color.equalsIgnoreCase("corteza")){
encodedColor="#568BA2";
}
else
encodedColor = "#38DF87";
return encodedColor;
}
private void replaceIDUserToUsername(String idUser){
service = new ServicesFactory(sp);
service.getUserService().getUser(idUser).enqueue(new Callback<User>() {
@Override
public void onResponse(@NotNull Call<User> call, @NotNull Response<User> response) {
User u = response.body();
assert u != null;
username = u.getUsername();
if(u.isAdmin()){
members.append("Admin: " + username + ";\n");
}
else
members.append("Other member: " + username + ";\n");
}
@Override
public void onFailure(Call<User> call, Throwable t) {
//TODO
}
});
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape
android:shape="rectangle" >
<solid
android:color="@color/colorAccent" >
</solid>
<corners
android:radius="11dp" >
</corners>
</shape>
</selector>

View File

@ -1,35 +1,198 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Space
android:layout_width="match_parent"
android:layout_height="27dp" />
android:scrollIndicators="right"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title_board"
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Board title: " />
android:orientation="vertical">
<Space
<TextView
android:id="@+id/textViewInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="1dp"
android:text="@string/info_board"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:text="@string/description"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/descriptionTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/defaultTxt" />
<View
android:id="@+id/divider1"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF008577"
android:visibility="visible" />
<TextView
android:id="@+id/members"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="3dp"
android:text="@string/members"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/membersTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/defaultTxt" />
<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF008577"
android:visibility="visible" />
<TextView
android:id="@+id/permission"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="3dp"
android:text="@string/permission"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/permissionTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text="@string/defaultTxt" />
<View
android:id="@+id/divider3"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FF008577"
android:visibility="visible" />
<TextView
android:id="@+id/labels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="3dp"
android:text="@string/labels"
android:textSize="18sp"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewID"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_marginRight="8dp"
android:nestedScrollingEnabled="true" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="27dp" />
android:layout_height="match_parent">
<Button
android:id="@+id/getLists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get lists" />
<com.google.android.material.button.MaterialButton
android:id="@+id/getLists"
style="@style/AppTheme.RoundedCornerMaterialButton"
android:layout_width="271dp"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="70dp"
android:stateListAnimator="@android:anim/fade_in"
android:text="@string/view_lists_button_name"
android:textAlignment="center"
app:backgroundTint="#80CBC4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/modifiedDate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="50dp"
android:text="@string/modified_at"
android:textAlignment="textEnd"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/getLists"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/createdDate"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="50dp"
android:text="@string/created_at"
android:textAlignment="viewStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/modifiedDate"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/getLists"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -1,3 +1,4 @@
<resources>
<dimen name="fab_margin">16dp</dimen>
<dimen name="padding">10dp</dimen>
</resources>

View File

@ -1,3 +1,12 @@
<resources>
<string name="app_name">wedroid</string>
<string name="view_lists_button_name">View lists</string>
<string name="info_board">Info board</string>
<string name="description">-Description:</string>
<string name="defaultTxt">***</string>
<string name="members">-Members:</string>
<string name="permission">-Permission:</string>
<string name="labels">-Labels:</string>
<string name="modified_at">Modified at:</string>
<string name="created_at">Created at:</string>
</resources>

View File

@ -15,7 +15,10 @@
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:background">@drawable/rounded_shape</item>
</style>
</resources>