Commit 8efdffcf authored by Ivan Del Pino's avatar Ivan Del Pino Committed by Rafael Jesus Hernández Vasquez

feat(view): add spinner to filter request and show result

Signed-off-by: 's avatarIvan Del Pino <idelpino@teclib.com>
parent a457dcfb
......@@ -30,7 +30,10 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Spinner;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
......@@ -51,14 +54,17 @@ public class MainActivity extends AppCompatActivity {
private List<String> resultList = new ArrayList<>();
private GLPI glpi;
private ActivityAdapter activityAdapter;
private int prevSize;
private Spinner spinnerTest;
private ExampleData data;
private ProgressBar progressBar;
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ExampleData data = new ExampleData();
data = new ExampleData();
data.setEmail("greatsupport@example.com");
data.setEmail("5e9d551afc181984042a985fd6552ea8400c190c4f1f61d7838cf8a1b88668f3");
data.setName("Great support");
......@@ -78,57 +84,66 @@ public class MainActivity extends AppCompatActivity {
glpi = new GLPI(MainActivity.this, data.getUrl());
RecyclerView recyclerView = findViewById(R.id.recyclerViewApi);
progressBar = findViewById(R.id.progressBar);
recyclerView = findViewById(R.id.recyclerViewApi);
resultList.add("Ivans");
activityAdapter = new ActivityAdapter(resultList);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(activityAdapter);
final Button btnInit = findViewById(R.id.btnInit);
btnInit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnInit(data);
}
});
spinnerTest = findViewById(R.id.spinnerTest);
ArrayList<String> list = new ArrayList<>();
list.add("Init Session");
list.add("Kill session");
list.add("Call Request");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTest.setAdapter(adapter);
Button btn = findViewById(R.id.btnCall);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnCall();
}
});
Button btnKill = findViewById(R.id.btnKill);
btnKill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnKill();
switch (spinnerTest.getSelectedItem().toString()) {
case "Init Session":
btnInit();
break;
case "Kill session":
btnKill();
break;
case "Call Request":
btnCall();
break;
}
}
});
}
private void btnKill() {
prevSize = resultList.size();
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.killSession(new GLPI.VoidCallback() {
@Override
public void onResponse(String response) {
FlyveLog.i("killSession: %s", response.toString());
updateAdapter("Success: Kill Session");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.e("killSession: %s", errorMessage);
updateAdapter("Error: Kill Session");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
private void btnInit(ExampleData data) {
prevSize = resultList.size();
private void btnInit() {
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.initSessionByUserToken(data.getUserToken(), new GLPI.InitSessionCallback() {
@Override
......@@ -146,17 +161,22 @@ public class MainActivity extends AppCompatActivity {
public void onResponse(InitSession response) {
FlyveLog.i("initSession: %s", response.getSessionToken());
updateAdapter("Success: Init Session Credentials");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
updateAdapter("Error: Init Session Credentials");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
private void btnCall() {
prevSize = resultList.size();
progressBar.setVisibility(View.VISIBLE);
resultList.clear();
glpi.getMyProfiles(new GLPI.JsonObjectCallback() {
@Override
......@@ -409,19 +429,22 @@ public class MainActivity extends AppCompatActivity {
public void onResponse(String response) {
FlyveLog.i("recoveryPassword: %s", response);
updateAdapter("Success: Reset Password");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(String errorMessage) {
FlyveLog.e("recoveryPassword: %s", errorMessage);
updateAdapter("Error: Reset Password");
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
private void updateAdapter(String message) {
resultList.add(message);
activityAdapter.notifyItemRangeRemoved(0, prevSize);
activityAdapter.notifyItemRangeInserted(0, resultList.size());
activityAdapter.notifyDataSetChanged();
}
}
......@@ -23,58 +23,40 @@
android:id="@+id/constraintLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnKill"
<Spinner
android:id="@+id/spinnerTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="@string/kill_session"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnCall" />
<Button
android:id="@+id/btnInit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="@string/init_session"
app:layout_constraintHorizontal_bias="0.101"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:layout_gravity="center" />
<Button
android:id="@+id/btnCall"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:text="@string/call_apis"
android:text="@string/test"
app:layout_constraintHorizontal_bias="0.13"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnInit" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
......@@ -82,7 +64,7 @@
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
......@@ -95,14 +77,35 @@
app:layout_constraintTop_toBottomOf="@+id/constraintLayout"
app:layout_constraintVertical_bias="0.0">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewApi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textResult"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:padding="5dp"
android:textSize="18sp"
android:text="" />
<View
......
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:maxLength="25"
android:padding="5dip"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
\ No newline at end of file
......@@ -2,5 +2,5 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorAccent">#293b8c</color>
</resources>
......@@ -4,4 +4,5 @@
<string name="call_apis">Call APIs</string>
<string name="kill_session">Kill Session</string>
<string name="init_session">Init Session</string>
<string name="test">Test</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment