Merge remote-tracking branch 'origin/feature_integrate_login' into feature_board_view
Some checks failed
continuous-integration/drone/push Build is failing

# Conflicts:
#	app/build.gradle
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/it/unisannio/ding/ids/wedroid/app/MainActivity.kt
#	app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/PreferenceReader.java
#	app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/PreferenceWriter.java
#	app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/ServicesFactory.kt
#	app/src/main/java/it/unisannio/ding/ids/wedroid/app/util/SharedPreferenceHelper.kt
#	app/src/main/res/layout/activity_main.xml
#	app/src/main/res/values/dimens.xml
#	app/src/main/res/values/strings.xml
#	app/src/main/res/values/styles.xml
#	build.gradle
This commit is contained in:
Umberto Furno 2020-01-10 16:27:30 +01:00
parent 7295be413d
commit 8b6104e0fa
19 changed files with 152 additions and 152 deletions

View File

@ -29,7 +29,7 @@
<activity
android:name=".view.WListsListActivity"
android:label="WList"
android:theme="@style/AppTheme.NoActionBar"/>
android:theme="@style/AppTheme.NoActionBar" />
<activity

View File

@ -19,7 +19,7 @@ public interface WListDao {
LiveData<List<WList>> getAllWList();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(WList wList);
void insert(WList wList);
@Delete
void delete(WList wList);

View File

@ -12,6 +12,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.Board;
@Database(entities = Board.class, version = 1, exportSchema = false)
public abstract class BoardDatabase extends RoomDatabase {
private static volatile BoardDatabase INSTANCE;
public abstract BoardDao boardDao();
public static BoardDatabase getDatabase(Context context) {

View File

@ -12,6 +12,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
@Database(entities = WList.class, version = 2, exportSchema = false)
public abstract class WListDatabase extends RoomDatabase {
private static volatile WListDatabase INSTANCE;
public abstract WListDao wListDao();
public static WListDatabase getDatabase(Context context) {

View File

@ -12,4 +12,4 @@ data class WList(
fun it.unisannio.ding.ids.wedroid.wrapper.entity.WList.convert(): WList {
return WList(this.id, this.title)
}
}

View File

@ -151,7 +151,7 @@ class BoardRepository(
private suspend fun removeOldBoardsFromDb(boards: Collection<Board>) {
allBoards.value?.minus(boards)
?.forEach {
dao.delete(it)
dao.delete(it)
}
}

View File

@ -21,7 +21,7 @@ class WListRepository(
private val reader: PreferenceReader
) {
val allWLists: LiveData<MutableList<WList>> by lazy{
val allWLists: LiveData<MutableList<WList>> by lazy {
dao.allWList
}
@ -29,7 +29,7 @@ class WListRepository(
synchronize()
}
fun synchronize() {
fun synchronize() {
service.getAllList(reader.boardId)
.enqueue(object :
Callback<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>> {
@ -50,8 +50,8 @@ class WListRepository(
}
private fun synchronizeCallback(
response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>)
{
response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>
) {
if (!response.isSuccessful) {
logNetworkError("${response.code()} ${response.message()}")
return
@ -64,10 +64,13 @@ class WListRepository(
removeOldWListsFromDb(wLists)
}
fun deleteWList(idBoard: String, idWList:String) {
fun deleteWList(idBoard: String, idWList: String) {
service.deleteList(idBoard, idWList).enqueue(
object : Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> {
override fun onFailure(call: Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>, t: Throwable) {
override fun onFailure(
call: Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
t: Throwable
) {
logNetworkError(t.message)
}
@ -76,21 +79,21 @@ class WListRepository(
response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>
) {
CoroutineScope(Dispatchers.IO).launch {
deleteWListCallBack(response,idWList)
deleteWListCallBack(response, idWList)
}
}
})
}
private fun deleteWListCallBack(response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
id: String) {
private fun deleteWListCallBack(
response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
id: String
) {
if (!response.isSuccessful) {
logNetworkError("${response.code()} ${response.message()}")
return
}
dao.delete(WList(id))
}
private fun addNewWListToDb(wLists: Collection<WList>) {
@ -99,7 +102,6 @@ class WListRepository(
}
}
private fun removeOldWListsFromDb(wLists: Collection<WList>) {
allWLists.value?.minus(wLists)
?.forEach {
@ -111,4 +113,4 @@ class WListRepository(
private fun logNetworkError(message: String?) {
Log.e("RETROFIT", message)
}
}
}

View File

@ -2,7 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
public interface PreferenceReader {
String getBaseUrl();
String getUserId();
String getToken();
String getBoardId();
}

View File

@ -2,7 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
public interface PreferenceWriter {
void setBaseUrl(String baseUrl);
void setUserId(String userId);
void setToken(String token);
void setBoardId(String boardId);
}

View File

@ -1,6 +1,12 @@
package it.unisannio.ding.ids.wedroid.app.util
import it.unisannio.ding.ids.wedroid.wrapper.api.*
import it.unisannio.ding.ids.wedroid.wrapper.api.BoardService
import it.unisannio.ding.ids.wedroid.wrapper.api.CardCommentService
import it.unisannio.ding.ids.wedroid.wrapper.api.CardService
import it.unisannio.ding.ids.wedroid.wrapper.api.ChecklistService
import it.unisannio.ding.ids.wedroid.wrapper.api.UserService
import it.unisannio.ding.ids.wedroid.wrapper.api.ListService
import it.unisannio.ding.ids.wedroid.wrapper.api.SwimlanesService
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

View File

@ -2,7 +2,7 @@ package it.unisannio.ding.ids.wedroid.app.util
import android.content.Context
class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWriter {
class SharedPreferenceHelper(context: Context) : PreferenceReader, PreferenceWriter {
private val sp = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE)
override fun getBaseUrl(): String? {
@ -20,8 +20,7 @@ class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWr
override fun setBaseUrl(baseUrl: String?) {
val editor = sp.edit()
editor.putString("url", baseUrl).apply()
}
}
override fun setUserId(userId: String?) {
val editor = sp.edit()

View File

@ -15,6 +15,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -38,7 +39,7 @@ public class BoardViewActivity extends AppCompatActivity {
private TextView description, members, permission, creationDate, lastModificationDate;
private View divider1, divider2, divider3;
private ListView listView;
private Button getListsButton;
private Button getListsButton;
private SharedPreferenceHelper sp;
private ServicesFactory service;
private Toolbar myToolbar;
@ -56,7 +57,7 @@ public class BoardViewActivity extends AppCompatActivity {
swipeRefreshLayout.setRefreshing(false);
Intent i = getIntent();
idBoard= i.getStringExtra("idBoard");
idBoard = i.getStringExtra("idBoard");
getListsButton = findViewById(R.id.getLists);
description = findViewById(R.id.descriptionTxt);
@ -66,7 +67,7 @@ public class BoardViewActivity extends AppCompatActivity {
lastModificationDate = findViewById(R.id.modifiedDate);
divider1 = findViewById(R.id.divider1);
divider2 = findViewById(R.id.divider2);
divider3= findViewById(R.id.divider3);
divider3 = findViewById(R.id.divider3);
listView = findViewById(R.id.listViewID);
sp = new SharedPreferenceHelper(this);
@ -101,7 +102,7 @@ public class BoardViewActivity extends AppCompatActivity {
public void onResponse(@NotNull Call<Board> call, @NotNull Response<Board> response) {
assert response.body() != null;
board = response.body();
if (board.getId()==null) {
if (board.getId() == null) {
Toast.makeText(
getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted),
@ -134,7 +135,7 @@ public class BoardViewActivity extends AppCompatActivity {
+ board.getCreatedAt());
lastModificationDate.setText(R.string.modified_at);
lastModificationDate.append("\n"
+ board.getModifiedAt());
+ board.getModifiedAt());
divider1.setBackgroundColor(boardColor);
divider2.setBackgroundColor(boardColor);
@ -149,57 +150,47 @@ public class BoardViewActivity extends AppCompatActivity {
listView.setAdapter(adapter);
}
}
@Override
public void onFailure (@NotNull Call < Board > call, @NotNull Throwable t){
Toast.makeText(getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted),
Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(@NotNull Call<Board> call, @NotNull Throwable t) {
Toast.makeText(getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted),
Toast.LENGTH_LONG).show();
}
});
}
private String encodeColor(String color){
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
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){
private void replaceIDUserToUsername(String idUser) {
service = new ServicesFactory(sp);
service.getUserService().getUser(idUser).enqueue(new Callback<User>() {
@Override
@ -207,10 +198,9 @@ public class BoardViewActivity extends AppCompatActivity {
User u = response.body();
assert u != null;
username = u.getUsername();
if(u.isAdmin()){
if (u.isAdmin()) {
members.append("Admin: " + username + ";\n");
}
else
} else
members.append("Other member: " + username + ";\n");
}

View File

@ -42,7 +42,7 @@ class LoginActivity : AppCompatActivity() {
val passwordText = password.text.toString()
val instanceServerText = instanceServer.text.toString()
if (!URLUtil.isValidUrl(instanceServerText)){
if (!URLUtil.isValidUrl(instanceServerText)) {
Toast.makeText(this, R.string.login_unformed_instance, Toast.LENGTH_LONG)
.show()
return

View File

@ -23,7 +23,7 @@ import java.util.Objects;
import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.viewmodel.WListsListViewModel;
import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.app.view.adapter.WListsAdapter;
@ -50,7 +50,7 @@ public class WListsListActivity extends AppCompatActivity {
String boardTitle = i.getStringExtra("barTitle");
Objects.requireNonNull(getSupportActionBar()).setTitle(boardTitle);
barColor = i.getIntExtra("barColor", 0);
setResult(WListsListActivity.RESULT_OK,i);
setResult(WListsListActivity.RESULT_OK, i);
myToolbar.setBackgroundColor(barColor);

View File

@ -42,7 +42,6 @@ class BoardsListAdapter internal constructor(
val intent = Intent(holder.itemView.context, BoardViewActivity::class.java)
intent.putExtra("idBoard", board.id)
holder.itemView.context.startActivity(intent)
}
}

View File

@ -40,20 +40,21 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
private ServicesFactory service;
private SharedPreferenceHelper sp;
public WListsAdapter(Context context){
public WListsAdapter(Context context) {
mInflater = LayoutInflater.from(context);
mContext=context;
mContext = context;
sp = new SharedPreferenceHelper(mContext);
service = new ServicesFactory(sp);
}
class WListViewHolder extends RecyclerView.ViewHolder{
class WListViewHolder extends RecyclerView.ViewHolder {
private final TextView wListItemView;
ListView listView;
Button button;
private WListViewHolder(View itemView){
private WListViewHolder(View itemView) {
super(itemView);
wListItemView= itemView.findViewById(R.id.wListTitle);
wListItemView = itemView.findViewById(R.id.wListTitle);
listView = itemView.findViewById(R.id.listViewCard);
button = itemView.findViewById(R.id.buttonAddCard);
}
@ -74,28 +75,29 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
final List<String> cardTitle = new ArrayList<>();
service.getCardService().getAllCards(sp.getBoardId(), current.getId()).enqueue(
new Callback<List<Card>>() {
@Override
public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) {
assert response.body() != null;
for(int i = 0; i<response.body().size(); i++){
cardTitle.add(response.body().get(i).getTitle());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_list_item_1, cardTitle);
holder.listView.setAdapter(adapter);
holder.wListItemView.setText(current.getTitle());
holder.button.setText("Add Card to " + current.getTitle());
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInputDialog(current.getId());
public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) {
assert response.body() != null;
for (int i = 0; i < response.body().size(); i++) {
cardTitle.add(response.body().get(i).getTitle());
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_list_item_1, cardTitle);
holder.listView.setAdapter(adapter);
holder.wListItemView.setText(current.getTitle());
holder.button.setText("Add Card to " + current.getTitle());
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInputDialog(current.getId());
}
});
}
@Override
public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) {
}
});
}
@Override
public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) {
}
});
/*position of the old content holder**/
@ -112,7 +114,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
else return 0;
}
public void setWLists(List<WList> wList){
public void setWLists(List<WList> wList) {
mWLists = wList;
notifyDataSetChanged();
}
@ -124,64 +126,64 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setView(promptView);
final EditText editText = promptView.findViewById(R.id.edittext);
final EditText editText = promptView.findViewById(R.id.edittext);
// setup a dialog window
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if(!editText.getText().toString().matches("")) {
if (!editText.getText().toString().matches("")) {
service.getSwimlanesService().getAllSwimlanes(sp.getBoardId())
.enqueue(new Callback<List<Swimlane>>() {
@Override
public void onResponse(@NotNull Call<List<Swimlane>> call,
@NotNull Response<List<Swimlane>> response) {
String idDefaultSwimlane = null;
assert response.body() != null;
for(Swimlane swim: response.body()){
if(swim.getTitle().equalsIgnoreCase("default"))
idDefaultSwimlane=swim.getTitle();
}
final Card card = new Card();
card.setTitle(editText.getText().toString());
card.setAuthorId(sp.getUserId());
card.setSwimlaneId(idDefaultSwimlane);
//card.setDescription("new card from app");
service.getListService().getList(sp.getBoardId(), current).enqueue(new Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>() {
@Override
public void onResponse(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> response) {
public void onResponse(@NotNull Call<List<Swimlane>> call,
@NotNull Response<List<Swimlane>> response) {
String idDefaultSwimlane = null;
assert response.body() != null;
for (Swimlane swim : response.body()) {
if (swim.getTitle().equalsIgnoreCase("default"))
idDefaultSwimlane = swim.getTitle();
}
final Card card = new Card();
card.setTitle(editText.getText().toString());
card.setAuthorId(sp.getUserId());
card.setSwimlaneId(idDefaultSwimlane);
//card.setDescription("new card from app");
service.getListService().getList(sp.getBoardId(), current).enqueue(new Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>() {
@Override
public void onResponse(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> response) {
service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() {
@Override
public void onResponse(@NotNull Call<Card> call, @NotNull Response<Card> response){
if(response.isSuccessful())
Toast.makeText(mContext, "card posted" ,
Toast.LENGTH_LONG).show();
else
Toast.makeText(mContext, "card doesn't posted" ,
Toast.LENGTH_LONG).show();
service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() {
@Override
public void onResponse(@NotNull Call<Card> call, @NotNull Response<Card> response) {
if (response.isSuccessful())
Toast.makeText(mContext, "card posted",
Toast.LENGTH_LONG).show();
else
Toast.makeText(mContext, "card doesn't posted",
Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
}
});
}
@Override
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
public void onFailure(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Throwable t) {
}
});
}
@Override
public void onFailure(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Throwable t) {
public void onFailure(@NotNull Call<List<Swimlane>> call, @NotNull Throwable t) {
}
});
}
@Override
public void onFailure(@NotNull Call<List<Swimlane>> call, @NotNull Throwable t) {
}
});
}
else
} else
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
}
})

View File

@ -1,4 +1,4 @@
package it.unisannio.ding.ids.wedroid.app.viewmodel;
package it.unisannio.ding.ids.wedroid.app.viewModel;
import android.app.Application;
@ -30,7 +30,7 @@ public class WListsListViewModel extends AndroidViewModel {
allWLists = wListRepository.getAllWLists();
}
public LiveData<List<WList>> getAllWLists(){
public LiveData<List<WList>> getAllWLists() {
return allWLists;
}

View File

@ -1,12 +1,7 @@
<?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 android:shape="rectangle">
<solid android:color="@color/colorAccent"></solid>
<corners android:radius="11dp"></corners>
</shape>
</selector>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/wListTitle"
@ -17,8 +17,7 @@
<ListView
android:id="@+id/listViewCard"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
android:layout_height="match_parent" />
<Button
android:id="@+id/buttonAddCard"