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

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


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