poprawki błędów
This commit is contained in:
parent
0df52ec13f
commit
4a8c20ca8b
2
app/.gitignore
vendored
2
app/.gitignore
vendored
@ -1 +1 @@
|
||||
/build
|
||||
/build
|
||||
|
@ -1,29 +1,30 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "michalpawlaczyk.shoplist"
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation 'com.android.support:design:28.0.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "michalpawlaczyk.shoplist"
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation 'com.android.support:design:28.0.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
implementation 'com.android.volley:volley:1.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
|
42
app/proguard-rules.pro
vendored
42
app/proguard-rules.pro
vendored
@ -1,21 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
@ -1,26 +1,26 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("michalpawlaczyk.shoplist", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("michalpawlaczyk.shoplist", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="michalpawlaczyk.shoplist">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning"
|
||||
android:fullBackupContent="true">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".FloatingAction"/>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="michalpawlaczyk.shoplist">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="m">
|
||||
<activity android:name=".MainActivity"/>
|
||||
<activity android:name=".FloatingAction"
|
||||
android:parentActivityName=".MainActivity"
|
||||
/>
|
||||
<activity android:name=".LoginActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".RegisterActivity"/>
|
||||
<activity android:name=".UserAreaActivity"
|
||||
android:parentActivityName=".MainActivity"/>
|
||||
<receiver android:name=".ReminderReciver"/>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
</manifest>
|
@ -1,17 +0,0 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class AddProductFragment extends Fragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.product_add, container, false);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "Products.db";
|
||||
private static final String TABLE_NAME = "products_list";
|
||||
private static final String COL_1 = "ID";
|
||||
private static final String COL_2 = "NAME";
|
||||
|
||||
DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("create table " + TABLE_NAME + "(ID INTEGER, NAME TEXT) ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
boolean insertData(String tableName, String name){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(COL_2, name);
|
||||
long result = db.insert(tableName, null, contentValues);
|
||||
return result != -1;
|
||||
|
||||
}
|
||||
|
||||
Cursor getChecekData(String tableName){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
return db.rawQuery("select * from " + tableName, null);
|
||||
}
|
||||
Cursor getAllTableName(){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
return db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
|
||||
}
|
||||
boolean updateData (String name, String newName){
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(COL_2, newName);
|
||||
db.update(TABLE_NAME, contentValues, "NAME = ?", new String[]{ name });
|
||||
return true;
|
||||
}
|
||||
|
||||
Integer deleteData (String tableName, String name) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
return db.delete(tableName, "NAME = ?", new String[] { name });
|
||||
}
|
||||
void userCreateTable(String tableName){
|
||||
SQLiteDatabase db = this.getWritableDatabase();/*
|
||||
db.rawQuery("CREATE TABLE IF NOT EXISTS " + tableName +
|
||||
" ( ID INTEGER, " +
|
||||
"NAME TEXT )", null);*/
|
||||
String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS " + tableName +
|
||||
" ( ID INTEGER, " +
|
||||
"NAME TEXT )";
|
||||
db.execSQL(CREATE_TABLE);
|
||||
db.close();
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class EditFragment extends Fragment {
|
||||
private Button addListBtn;
|
||||
EditText listNameText;
|
||||
String text;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.popup_dialog, container, false);
|
||||
addListBtn = view.findViewById(R.id.addListBtn);
|
||||
listNameText = view.findViewById(R.id.listNameText);
|
||||
btnClick();
|
||||
return view;
|
||||
|
||||
}
|
||||
public void btnClick(){
|
||||
addListBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
text = listNameText.getText().toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
public String getText(){
|
||||
return text;
|
||||
}
|
||||
}
|
@ -1,72 +1,78 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FloatingAction extends AppCompatActivity {
|
||||
private Button addListBtn;
|
||||
EditText listNameText;
|
||||
DatabaseHelper myDb;
|
||||
String chosenListID;
|
||||
ArrayList<String> productItem;
|
||||
ArrayAdapter<String> adapter2;
|
||||
ListView listProductView;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.popup_dialog);
|
||||
addListBtn = findViewById(R.id.addListBtn);
|
||||
listNameText = findViewById(R.id.listNameText);
|
||||
myDb = new DatabaseHelper(this);
|
||||
listProductView = findViewById(R.id.productsListView);
|
||||
productItem = new ArrayList<>();
|
||||
AddData();
|
||||
}
|
||||
public void AddData(){
|
||||
addListBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if(extras != null) {
|
||||
chosenListID = extras.getString("chosenListID");
|
||||
boolean isInserted = myDb.insertData(chosenListID, listNameText.getText().toString());
|
||||
if (isInserted) {
|
||||
Toast.makeText(FloatingAction.this, "Done", Toast.LENGTH_LONG).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(FloatingAction.this, "Something goes wrong!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
//reloadData();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void reloadData(){
|
||||
Cursor res = myDb.getChecekData(chosenListID);
|
||||
if(res.getCount() == 0){
|
||||
Toast.makeText(this, "No data to show", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
while (res.moveToNext()) {
|
||||
productItem.add(res.getString(1));
|
||||
|
||||
}
|
||||
adapter2 = new ArrayAdapter<>(this, R.layout.product_view, productItem);
|
||||
listProductView.setAdapter(adapter2);
|
||||
}
|
||||
}
|
||||
}
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.toolbox.JsonObjectRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FloatingAction extends AppCompatActivity {
|
||||
private Button addListBtn;
|
||||
EditText listNameText;
|
||||
String chosenListID;
|
||||
ArrayList<String> productItem;
|
||||
ListView listProductView;
|
||||
MainActivity mainActivity;
|
||||
private static final String URL = "http://150.254.129.198:8080";
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.popup_dialog);
|
||||
addListBtn = findViewById(R.id.addListBtn);
|
||||
listNameText = findViewById(R.id.listNameText);
|
||||
listProductView = findViewById(R.id.productsListView);
|
||||
productItem = new ArrayList<>();
|
||||
listNameText.setHint("Podaj nazwę produktu");
|
||||
AddData();
|
||||
|
||||
|
||||
}
|
||||
public void AddData(){
|
||||
addListBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if(extras != null) {
|
||||
chosenListID = extras.getString("chosenListID");
|
||||
String text = listNameText.getText().toString();
|
||||
final SharedPreferences settings = Objects.requireNonNull(getApplicationContext()).getSharedPreferences("userInfo", Context.MODE_PRIVATE);
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("tableName", chosenListID);
|
||||
postParam.put("rowData", text);
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
|
||||
Request.Method.POST,
|
||||
URL + "/addData?"+settings.getString("token",""),
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
}
|
||||
}, null
|
||||
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(Objects.requireNonNull(getApplicationContext()));
|
||||
queue.add(jsonObjectRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
127
app/src/main/java/michalpawlaczyk/shoplist/LoginActivity.java
Normal file
127
app/src/main/java/michalpawlaczyk/shoplist/LoginActivity.java
Normal file
@ -0,0 +1,127 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.NetworkError;
|
||||
import com.android.volley.ParseError;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.ServerError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.JsonObjectRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import org.json.JSONObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
private static final String URL = "http://150.254.129.198:8080/login";
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.login_activity);
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userInfo", MODE_PRIVATE);
|
||||
if(settings.contains("username")){
|
||||
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
final EditText usernameET = findViewById(R.id.usernameLogin);
|
||||
final EditText passwordET = findViewById(R.id.passwordLogin);
|
||||
final Button signinBtn = findViewById(R.id.signinBtn);
|
||||
final TextView signupTV = findViewById(R.id.signupText);
|
||||
|
||||
|
||||
signupTV.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
|
||||
LoginActivity.this.startActivity(registerIntent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
signinBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final String username = usernameET.getText().toString();
|
||||
final String password = passwordET.getText().toString();
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("login", username);
|
||||
postParam.put("password", password);
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
|
||||
Request.Method.POST,
|
||||
URL,
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
||||
LoginActivity.this.startActivity(intent);
|
||||
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
String token = username+":"+password;
|
||||
token = android.util.Base64.encodeToString(token.getBytes(),0);
|
||||
editor.putString("username", username);
|
||||
editor.putString("password", password);
|
||||
editor.putString("token", token);
|
||||
editor.apply();
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener(){
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
if (error instanceof ServerError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if(error instanceof AuthFailureError){
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
|
||||
builder.setMessage("Login Failed. Username or password incorrect")
|
||||
.setNegativeButton("Retry", null)
|
||||
.create()
|
||||
.show();
|
||||
} else if(error instanceof NetworkError){
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
}else if(error instanceof ParseError){
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
||||
LoginActivity.this.startActivity(intent);
|
||||
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
String token = username+":"+password;
|
||||
token = android.util.Base64.encodeToString(token.getBytes(),0);
|
||||
editor.putString("username", username);
|
||||
editor.putString("password", password);
|
||||
editor.putString("token", token);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,234 +1,428 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
private DrawerLayout mDraverLayout;
|
||||
private ActionBarDrawerToggle mToggle;
|
||||
DatabaseHelper myDb;
|
||||
ArrayList<String> listItem;
|
||||
ArrayList<String> productItem;
|
||||
ArrayAdapter<String> adapter;
|
||||
ArrayAdapter<String> adapter2;
|
||||
ListView listNameView;
|
||||
ListView listProductView;
|
||||
CheckedTextView ctvProduct;
|
||||
Button editItem;
|
||||
FloatingActionButton fab;
|
||||
String listProductID;
|
||||
String chosenListID;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
mDraverLayout = findViewById(R.id.drawer_layout);
|
||||
mToggle = new ActionBarDrawerToggle(this, mDraverLayout, R.string.Open, R.string.Close);
|
||||
mDraverLayout.addDrawerListener(mToggle);
|
||||
mToggle.syncState();
|
||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
NavigationView mNavigationView = findViewById(R.id.navView);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
myDb = new DatabaseHelper(this);
|
||||
listItem = new ArrayList<>();
|
||||
listNameView = findViewById(R.id.listView);
|
||||
listProductView = findViewById(R.id.productsListView);
|
||||
ctvProduct = findViewById(R.id.productCheck);
|
||||
productItem = new ArrayList<>();
|
||||
viewTableName();
|
||||
fab = findViewById(R.id.fab);
|
||||
listProductView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, FloatingAction.class);
|
||||
intent.putExtra("chosenListID", chosenListID);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
listProductView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
listProductID = parent.getItemAtPosition(position).toString();
|
||||
/*
|
||||
if(listProductView.isItemChecked(position)) {
|
||||
ctvProduct.setPaintFlags(ctvProduct.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
else {
|
||||
ctvProduct.setPaintFlags(ctvProduct.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
}*/
|
||||
}
|
||||
});
|
||||
listNameView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
chosenListID = parent.getItemAtPosition(position).toString();
|
||||
viewCheckData(chosenListID);
|
||||
}
|
||||
});
|
||||
|
||||
registerForContextMenu(listProductView);
|
||||
//registerForContextMenu(listNameView);
|
||||
|
||||
/*
|
||||
ctvProduct.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(ctvProduct.isChecked()){
|
||||
ctvProduct.setChecked(false);
|
||||
}
|
||||
else
|
||||
ctvProduct.setChecked(true);
|
||||
}
|
||||
}
|
||||
);*/
|
||||
}
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
getMenuInflater().inflate(R.menu.context_menu, menu);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.deleteItem:
|
||||
Integer result = myDb.deleteData(chosenListID, listProductID);
|
||||
System.out.println(listProductID);
|
||||
if(result > 0){
|
||||
reloadData();
|
||||
}
|
||||
else {
|
||||
reloadData();
|
||||
Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
case R.id.editItem:
|
||||
/*
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||
new EditFragment()).commit();
|
||||
EditFragment editFragment = new EditFragment();
|
||||
String tmp = editFragment.getText();
|
||||
boolean result2 = myDb.updateData(chosenListID, tmp);
|
||||
if(result2){
|
||||
reloadData();
|
||||
}
|
||||
else {
|
||||
reloadData();
|
||||
Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}*/
|
||||
Toast.makeText(MainActivity.this, "Not supported yet", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//Navigation items
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()){
|
||||
case R.id.AddList:
|
||||
((FrameLayout)findViewById(R.id.content_frame)).removeAllViews();
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||
new MenuFragment()).commit();
|
||||
break;
|
||||
}
|
||||
mDraverLayout.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void viewCheckData(String tableName){
|
||||
Cursor res = myDb.getChecekData(tableName);
|
||||
adapter2 = new ArrayAdapter<>(this, R.layout.product_view, productItem);
|
||||
listProductView.setAdapter(adapter2);
|
||||
if(adapter2.getCount() > 0){
|
||||
adapter2.clear();
|
||||
}
|
||||
while (res.moveToNext()) {
|
||||
productItem.add(res.getString(1));
|
||||
|
||||
}
|
||||
adapter2 = new ArrayAdapter<>(this, R.layout.product_view, productItem);
|
||||
listProductView.setAdapter(adapter2);
|
||||
}
|
||||
public void reloadData(){
|
||||
Cursor res = myDb.getChecekData(chosenListID);
|
||||
adapter2.clear();
|
||||
if(res.getCount() == 0){
|
||||
Toast.makeText(this, "No data to show", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
while (res.moveToNext()) {
|
||||
productItem.add(res.getString(1));
|
||||
|
||||
}
|
||||
adapter2 = new ArrayAdapter<>(this, R.layout.product_view, productItem);
|
||||
listProductView.setAdapter(adapter2);
|
||||
}
|
||||
}
|
||||
|
||||
public void viewTableName(){
|
||||
Cursor res = myDb.getAllTableName();
|
||||
if (res.moveToFirst()) {
|
||||
while ( !res.isAfterLast() ) {
|
||||
listItem.add(res.getString(res.getColumnIndex("name")));
|
||||
System.out.println(res.getString( res.getColumnIndex("name")));
|
||||
res.moveToNext();
|
||||
}
|
||||
}
|
||||
adapter = new ArrayAdapter<>(this, R.layout.list_view, listItem);
|
||||
listNameView.setAdapter(adapter);
|
||||
}
|
||||
public void reloadTableName(){
|
||||
Cursor res = myDb.getAllTableName();
|
||||
adapter.clear();
|
||||
if (res.moveToFirst()) {
|
||||
while ( !res.isAfterLast() ) {
|
||||
listItem.add( res.getString( res.getColumnIndex("name")) );
|
||||
res.moveToNext();
|
||||
}
|
||||
}
|
||||
adapter = new ArrayAdapter<>(this, R.layout.list_view, listItem);
|
||||
listNameView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
}
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.NetworkError;
|
||||
import com.android.volley.ParseError;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.ServerError;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.JsonArrayRequest;
|
||||
import com.android.volley.toolbox.JsonObjectRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
private DrawerLayout mDraverLayout;
|
||||
private ActionBarDrawerToggle mToggle;
|
||||
ArrayList<String> listItem;
|
||||
ArrayList<String> productItem;
|
||||
ArrayAdapter adapter;
|
||||
ArrayAdapter<String> adapter2;
|
||||
ListView listNameView;
|
||||
ListView listProductView;
|
||||
CheckedTextView ctvProduct;
|
||||
Button editItem;
|
||||
FloatingActionButton fab;
|
||||
String listProductID;
|
||||
String chosenListID;
|
||||
String chosenTableID;
|
||||
ImageView accountImage;
|
||||
TextView accountHeader;
|
||||
private static final String URL = "http://150.254.129.198:8080";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
mDraverLayout = findViewById(R.id.drawer_layout);
|
||||
mToggle = new ActionBarDrawerToggle(this, mDraverLayout, R.string.Open, R.string.Close);
|
||||
mDraverLayout.addDrawerListener(mToggle);
|
||||
mToggle.syncState();
|
||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
NavigationView mNavigationView = findViewById(R.id.navView);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
listNameView = findViewById(R.id.listView);
|
||||
listProductView = findViewById(R.id.productsListView);
|
||||
ctvProduct = findViewById(R.id.productCheck);
|
||||
accountImage = findViewById(R.id.accountImage);
|
||||
productItem = new ArrayList<>();
|
||||
fab = findViewById(R.id.fab);
|
||||
listProductView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
getTableName();
|
||||
|
||||
accountHeader = findViewById(R.id.accountHeader);
|
||||
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userInfo", MODE_PRIVATE);
|
||||
final SharedPreferences lastTable = getApplicationContext().getSharedPreferences("userData", MODE_PRIVATE);
|
||||
chosenTableID = lastTable.getString("lastTable","");
|
||||
if(chosenTableID != null)
|
||||
viewTableData(chosenTableID);
|
||||
if(settings.getString("username","") != null){
|
||||
accountHeader.setText(settings.getString("username",""));
|
||||
}
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, FloatingAction.class);
|
||||
intent.putExtra("chosenListID", chosenListID);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
accountImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getApplicationContext(), UserAreaActivity.class);
|
||||
getApplicationContext().startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
listProductView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
listProductID = parent.getItemAtPosition(position).toString();
|
||||
Boolean isCheck = listProductView.isItemChecked(position);
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("tableName", chosenListID);
|
||||
postParam.put("productName", listProductID);
|
||||
postParam.put("isCheck", isCheck.toString());
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
|
||||
Request.Method.POST,
|
||||
URL + "/setItemCheck?" + settings.getString("token", ""),
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
}
|
||||
},null
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
}
|
||||
});
|
||||
|
||||
listProductView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
listProductID = parent.getItemAtPosition(position).toString();
|
||||
registerForContextMenu(listProductView);
|
||||
openContextMenu(listProductView);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
listNameView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
listProductView.setVisibility(View.VISIBLE);
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
chosenListID = parent.getItemAtPosition(position).toString();
|
||||
for (Fragment fragment:getSupportFragmentManager().getFragments()) {
|
||||
|
||||
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
|
||||
}
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userData", MODE_PRIVATE);
|
||||
@SuppressLint("CommitPrefEdits") SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putString("lastTable", chosenListID);
|
||||
viewTableData(chosenListID);
|
||||
}
|
||||
});
|
||||
listNameView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
final String deleteTableID = parent.getItemAtPosition(position).toString();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
builder.setMessage("Czy na pewno chcesz usunać listę "+deleteTableID+" ?")
|
||||
.setPositiveButton("Tak", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("tableName", deleteTableID);
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
|
||||
URL + "/deleteTable?" + settings.getString("token", ""),
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
}
|
||||
}, null);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
listItem.clear();
|
||||
getTableName();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Nie", null)
|
||||
.create()
|
||||
.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
//getMenuInflater().inflate(R.menu.context_menu, menu);
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userInfo", MODE_PRIVATE);
|
||||
|
||||
MenuItem delete = menu.add("Usuń");
|
||||
MenuItem edit = menu.add("Edytuj");
|
||||
|
||||
delete.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("tableName", chosenListID);
|
||||
postParam.put("rowData", listProductID);
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
|
||||
Request.Method.POST,
|
||||
URL + "/deleteData?" + settings.getString("token", ""),
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
|
||||
}
|
||||
},null
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
productItem.clear();
|
||||
viewTableData(chosenListID);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
edit.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
final EditText editText = new EditText(MainActivity.this);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
builder.setMessage("Podaj nową nazwę produktu")
|
||||
.setView(editText)
|
||||
.setPositiveButton("Zmień", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
Map<String, String> postParam= new HashMap<>();
|
||||
postParam.put("tableName", chosenListID);
|
||||
postParam.put("rowData", listProductID);
|
||||
postParam.put("newRow", editText.getText().toString());
|
||||
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
|
||||
URL + "/editData?" + settings.getString("token", ""),
|
||||
new JSONObject(postParam),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
}
|
||||
}, null);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
productItem.clear();
|
||||
viewTableData(chosenListID);
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (mToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//Navigation items
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()){
|
||||
case R.id.AddList:
|
||||
listProductView.setVisibility(View.GONE);
|
||||
fab.setVisibility(View.GONE);
|
||||
((FrameLayout)findViewById(R.id.content_frame)).removeAllViews();
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||
new MenuFragment()).commit();
|
||||
break;
|
||||
case R.id.ProductList:
|
||||
listItem.clear();
|
||||
getTableName();
|
||||
break;
|
||||
case R.id.Reminder:
|
||||
listProductView.setVisibility(View.GONE);
|
||||
fab.setVisibility(View.GONE);
|
||||
((FrameLayout)findViewById(R.id.content_frame)).removeAllViews();
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame,
|
||||
new ReminderFragment()).commit();
|
||||
break;
|
||||
}
|
||||
mDraverLayout.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void viewTableData(String tableName) {
|
||||
productItem = new ArrayList<>();
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userInfo", MODE_PRIVATE);
|
||||
|
||||
JsonArrayRequest jsonObjectRequest = new JsonArrayRequest(
|
||||
Request.Method.POST,
|
||||
URL + "/getTableRows?" + settings.getString("token", "")+":"+tableName, null,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
try {
|
||||
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject object = response.getJSONObject(i);
|
||||
productItem.add(object.getString("product"));
|
||||
String isCheck = object.getString("ischeck");
|
||||
if(isCheck.equals("true")){
|
||||
listProductView.setItemChecked(i, true);
|
||||
} else if(isCheck.equals("false")){
|
||||
listProductView.setItemChecked(i, false);
|
||||
}
|
||||
|
||||
}
|
||||
adapter2 = new ArrayAdapter<>(MainActivity.this, R.layout.product_view, productItem);
|
||||
listProductView.setAdapter(adapter2);
|
||||
for(int i = 0; i < response.length(); i++){
|
||||
JSONObject object = response.getJSONObject(i);
|
||||
String isCheck = object.getString("ischeck");
|
||||
if(isCheck.equals("true")){
|
||||
listProductView.setItemChecked(i, true);
|
||||
} else if(isCheck.equals("false")){
|
||||
listProductView.setItemChecked(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
if (error instanceof ServerError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if (error instanceof AuthFailureError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if (error instanceof NetworkError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if (error instanceof ParseError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
}
|
||||
|
||||
public void getTableName() {
|
||||
listItem = new ArrayList<>();
|
||||
final SharedPreferences settings = getApplicationContext().getSharedPreferences("userInfo", MODE_PRIVATE);
|
||||
JsonArrayRequest jsonObjectRequest = new JsonArrayRequest(
|
||||
Request.Method.POST,
|
||||
URL + "/getTableName?"+settings.getString("token",""), null,
|
||||
new Response.Listener<JSONArray>() {
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
try {
|
||||
|
||||
for (int i = 0; i < response.length(); i++) {
|
||||
JSONObject object = response.getJSONObject(i);
|
||||
listItem.add(object.getString("name"));
|
||||
}
|
||||
adapter = new ArrayAdapter<>(MainActivity.this, R.layout.list_view, listItem);
|
||||
listNameView.setAdapter(adapter);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener(){
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
if (error instanceof ServerError) {
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if(error instanceof AuthFailureError){
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
} else if(error instanceof NetworkError){
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
}else if(error instanceof ParseError){
|
||||
Toast.makeText(getBaseContext(), error.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
|
||||
queue.add(jsonObjectRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +1,71 @@
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
//import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MenuFragment extends Fragment{
|
||||
|
||||
private Button addListBtn;
|
||||
EditText listNameText;
|
||||
DatabaseHelper myDb;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.popup_dialog, container, false);
|
||||
addListBtn = view.findViewById(R.id.addListBtn);
|
||||
listNameText = view.findViewById(R.id.listNameText);
|
||||
myDb = new DatabaseHelper(getActivity());
|
||||
AddTable();
|
||||
return view;
|
||||
|
||||
}
|
||||
public void AddTable(){
|
||||
addListBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
myDb.userCreateTable(listNameText.getText().toString());
|
||||
((MainActivity)Objects.requireNonNull(getActivity())).reloadTableName();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
package michalpawlaczyk.shoplist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|