forked from narimetisaigopi/DBFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 23dabce
Showing
44 changed files
with
1,114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
def dbflow_version = "4.0.2" | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.example.dbflow" | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7: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' | ||
|
||
annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}" | ||
|
||
implementation "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}" | ||
implementation "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/example/dbflow/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.dbflow; | ||
|
||
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("com.example.dbflow", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.dbflow"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:name=".MyApp" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.dbflow; | ||
|
||
public interface ClickedMe { | ||
void setdata(StudentTable studentTable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.dbflow; | ||
|
||
|
||
import android.os.Build; | ||
|
||
import com.raizlabs.android.dbflow.annotation.Database; | ||
|
||
@Database(name = DBFlowDataBase.DBName,version = DBFlowDataBase.VERSION) | ||
public class DBFlowDataBase { | ||
public static final String DBName = "mydb"; | ||
public static final int VERSION = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.example.dbflow; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.TextView; | ||
|
||
import org.w3c.dom.Text; | ||
|
||
import java.util.List; | ||
|
||
public class ListViewAdapter extends BaseAdapter { | ||
Context context; | ||
List<StudentTable> studentTableList; | ||
ClickedMe clickedMe; | ||
ListViewAdapter(Context context, List<StudentTable> studentTableList,ClickedMe clickedMe){ | ||
this.context = context; | ||
this.studentTableList = studentTableList; | ||
this.clickedMe = clickedMe; | ||
} | ||
@Override | ||
public int getCount() { | ||
return studentTableList.size(); | ||
} | ||
|
||
@Override | ||
public Object getItem(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@Override | ||
public View getView(final int position, View view, ViewGroup parent) { | ||
view = LayoutInflater.from(context).inflate(R.layout.student_view_item,parent,false); | ||
TextView sid, name,marks,classOFStudy; | ||
name = view.findViewById(R.id.name); | ||
marks = view.findViewById(R.id.marks); | ||
classOFStudy = view.findViewById(R.id.classOFStudy); | ||
sid = view.findViewById(R.id.sid); | ||
|
||
|
||
sid.setText(""+studentTableList.get(position).getSid()); | ||
name.setText(studentTableList.get(position).getName()); | ||
marks.setText(""+studentTableList.get(position).getMarks()); | ||
classOFStudy.setText(""+studentTableList.get(position).getClassOfStudying()); | ||
|
||
view.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.d("data",studentTableList.get(position).toString()); | ||
clickedMe.setdata(studentTableList.get(position)); | ||
} | ||
}); | ||
|
||
return view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.example.dbflow; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ListView; | ||
import android.widget.Toast; | ||
|
||
import com.raizlabs.android.dbflow.sql.language.SQLite; | ||
|
||
import java.util.List; | ||
|
||
public class MainActivity extends AppCompatActivity implements ClickedMe{ | ||
|
||
EditText sid,name, marks, classofStudy; | ||
Button save,read,update,delete; | ||
|
||
ListView listView; | ||
|
||
ClickedMe clickedMe; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
|
||
name = findViewById(R.id.name); | ||
sid = findViewById(R.id.sid); | ||
marks = findViewById(R.id.marks); | ||
update = findViewById(R.id.update); | ||
|
||
classofStudy = findViewById(R.id.classofstudy); | ||
|
||
save = findViewById(R.id.save); | ||
read = findViewById(R.id.read); | ||
read = findViewById(R.id.read); | ||
delete = findViewById(R.id.delete); | ||
|
||
listView = findViewById(R.id.listview); | ||
|
||
|
||
save.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
StudentTable studentTable = new StudentTable(); | ||
studentTable.setName(name.getText().toString()); | ||
studentTable.setMarks(Integer.parseInt(marks.getText().toString())); | ||
studentTable.setClassOfStudying(Integer.parseInt(classofStudy.getText().toString())); | ||
|
||
if (studentTable.save()) { | ||
Toast.makeText(MainActivity.this, "saved success", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(MainActivity.this, "saved failed", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
|
||
read.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
populateListView(); | ||
} | ||
}); | ||
|
||
update.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
|
||
|
||
StudentTable studentTable = new StudentTable(); | ||
studentTable.setSid(Long.parseLong(sid.getText().toString())); // update operation | ||
studentTable.setName(name.getText().toString()); | ||
studentTable.setMarks(Integer.parseInt(marks.getText().toString())); | ||
studentTable.setClassOfStudying(Integer.parseInt(classofStudy.getText().toString())); | ||
|
||
if (studentTable.update()) { | ||
Toast.makeText(MainActivity.this, "Record of sid "+Long.parseLong(sid.getText().toString())+" updated ", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(MainActivity.this, "update failed", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
|
||
delete.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
StudentTable studentTable = new StudentTable(); | ||
studentTable.setSid(Long.parseLong(sid.getText().toString())); | ||
|
||
if (studentTable.delete()) { | ||
Toast.makeText(MainActivity.this, "Record of sid "+Long.parseLong(sid.getText().toString())+" deleted ", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(MainActivity.this, "delete failed", Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
|
||
void populateListView(){ | ||
List<StudentTable> studentTableList = SQLite.select().from(StudentTable.class).queryList(); | ||
ListViewAdapter listViewAdapter = new ListViewAdapter(MainActivity.this,studentTableList,this); | ||
listView.setAdapter(listViewAdapter); | ||
} | ||
|
||
@Override | ||
public void setdata(StudentTable studentTable) { | ||
Log.d("data2",studentTable.toString()); | ||
sid.setText(""+studentTable.getSid()); | ||
name.setText(""+studentTable.getName()); | ||
marks.setText(""+studentTable.getMarks()); | ||
classofStudy.setText(""+studentTable.getClassOfStudying()); | ||
} | ||
} |
Oops, something went wrong.