commit 49e4fd94ce3fa6c7594e52465827370170cdbae5 Author: Michal Date: Sat Dec 1 17:23:25 2018 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..b63d843 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,32 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b0c7b20 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ee87ab2 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,29 @@ +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' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +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 diff --git a/app/src/androidTest/java/michalpawlaczyk/shoplist/ExampleInstrumentedTest.java b/app/src/androidTest/java/michalpawlaczyk/shoplist/ExampleInstrumentedTest.java new file mode 100644 index 0000000..d8c7513 --- /dev/null +++ b/app/src/androidTest/java/michalpawlaczyk/shoplist/ExampleInstrumentedTest.java @@ -0,0 +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 Testing documentation + */ +@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()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..2da24c6 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/michalpawlaczyk/shoplist/DatabaseHelper.java b/app/src/main/java/michalpawlaczyk/shoplist/DatabaseHelper.java new file mode 100644 index 0000000..a739963 --- /dev/null +++ b/app/src/main/java/michalpawlaczyk/shoplist/DatabaseHelper.java @@ -0,0 +1,59 @@ +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"; + public static final String COL_1 = "ID"; + private static final String COL_2 = "NAME"; + + public DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, 1); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL("create table " + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT) "); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); + onCreate(db); + } + + public boolean insertData(String name){ + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put(COL_2, name); + long result = db.insert(TABLE_NAME, null, contentValues); + if (result == -1) { + return false; + } + else { + return true; + } + + } + + public Cursor getAlldata(){ + SQLiteDatabase db = this.getWritableDatabase(); + Cursor res = db.rawQuery("select * from " + TABLE_NAME, null); + return res; + } + public Cursor getAllTableName(){ + SQLiteDatabase db = this.getWritableDatabase(); + Cursor res = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null); + /* + if (res.moveToFirst()) { + while ( !res.isAfterLast() ) { + res.moveToNext(); + }*/ + return res; + } +} diff --git a/app/src/main/java/michalpawlaczyk/shoplist/MainActivity.java b/app/src/main/java/michalpawlaczyk/shoplist/MainActivity.java new file mode 100644 index 0000000..7b974c0 --- /dev/null +++ b/app/src/main/java/michalpawlaczyk/shoplist/MainActivity.java @@ -0,0 +1,104 @@ +package michalpawlaczyk.shoplist; + +import android.database.Cursor; +import android.support.annotation.NonNull; +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.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 listItem; + ArrayAdapter adapter; + ListView listNameView; + + + @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); + //viewData(); + viewTableName(); + + listNameView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String text = listNameView.getItemAtPosition(position).toString(); + Toast.makeText(MainActivity.this, " "+text, Toast.LENGTH_SHORT).show(); + } + }); + } + + @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: + getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, + new MenuFragment()).commit(); + break; + } + mDraverLayout.closeDrawer(GravityCompat.START); + return true; + } + + /*public void viewData(){ + Cursor res = myDb.getAlldata(); + if(res.getCount() == 0){ + Toast.makeText(this, "No data to show", Toast.LENGTH_SHORT).show(); + } + else { + while (res.moveToNext()) { + listItem.add(res.getString(1)); + + } + adapter = new ArrayAdapter<>(this, R.layout.list_view, listItem); + listNameView.setAdapter(adapter); + + } + }*/ + + public void viewTableName(){ + Cursor res = myDb.getAllTableName(); + 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); + } +} diff --git a/app/src/main/java/michalpawlaczyk/shoplist/MenuFragment.java b/app/src/main/java/michalpawlaczyk/shoplist/MenuFragment.java new file mode 100644 index 0000000..8dc5071 --- /dev/null +++ b/app/src/main/java/michalpawlaczyk/shoplist/MenuFragment.java @@ -0,0 +1,49 @@ +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 android.widget.Toast; + +public class MenuFragment extends Fragment { + + private Button addListBtn; + EditText listNameText; + DatabaseHelper myDb; + Context context; + + + @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()); + AddData(); + return view; + + } + + public void AddData(){ + addListBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean isInserted = myDb.insertData(listNameText.getText().toString()); + if(isInserted){ + Toast.makeText(getActivity(), "Done", Toast.LENGTH_LONG).show(); + } + else{ + Toast.makeText(getActivity(), "Something goes wrong!", Toast.LENGTH_LONG).show(); + } + + } + }); + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_baseline_account_circle_24px.xml b/app/src/main/res/drawable/ic_baseline_account_circle_24px.xml new file mode 100644 index 0000000..b845dc3 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_account_circle_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_add_24px.xml b/app/src/main/res/drawable/ic_baseline_add_24px.xml new file mode 100644 index 0000000..757f450 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_add_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..a37b4da --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/header.xml b/app/src/main/res/layout/header.xml new file mode 100644 index 0000000..98511d5 --- /dev/null +++ b/app/src/main/res/layout/header.xml @@ -0,0 +1,26 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_view.xml b/app/src/main/res/layout/list_view.xml new file mode 100644 index 0000000..11e81a0 --- /dev/null +++ b/app/src/main/res/layout/list_view.xml @@ -0,0 +1,16 @@ + + android:id="@+id/textView1" + android:layout_width="match_parent" + android:layout_height="40dp" + android:baselineAligned="false" + android:textSize="16sp" + android:gravity="center_vertical" + android:text="@string/Product_name" + android:textColor="#000" + + \ No newline at end of file diff --git a/app/src/main/res/layout/popup_dialog.xml b/app/src/main/res/layout/popup_dialog.xml new file mode 100644 index 0000000..9bca484 --- /dev/null +++ b/app/src/main/res/layout/popup_dialog.xml @@ -0,0 +1,26 @@ + + + + + +