diff --git a/ShowCaseApplication/.gitignore b/ShowCaseApplication/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/ShowCaseApplication/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties new file mode 100644 index 0000000..ab7a1b2 --- /dev/null +++ b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Fri Jan 22 14:08:31 PKT 2016 diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties.lock b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties.lock new file mode 100644 index 0000000..e172087 Binary files /dev/null and b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/cache.properties.lock differ diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileHashes.bin b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileHashes.bin new file mode 100644 index 0000000..73f4203 Binary files /dev/null and b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileHashes.bin differ diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin new file mode 100644 index 0000000..e8dbc1f Binary files /dev/null and b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin differ diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/outputFileStates.bin b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/outputFileStates.bin new file mode 100644 index 0000000..f27484f Binary files /dev/null and b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/outputFileStates.bin differ diff --git a/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin new file mode 100644 index 0000000..2dbf68e Binary files /dev/null and b/ShowCaseApplication/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin differ diff --git a/ShowCaseApplication/.idea/.name b/ShowCaseApplication/.idea/.name new file mode 100644 index 0000000..5de5895 --- /dev/null +++ b/ShowCaseApplication/.idea/.name @@ -0,0 +1 @@ +ShowCaseApplication \ No newline at end of file diff --git a/ShowCaseApplication/.idea/compiler.xml b/ShowCaseApplication/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/ShowCaseApplication/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/copyright/profiles_settings.xml b/ShowCaseApplication/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/ShowCaseApplication/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/gradle.xml b/ShowCaseApplication/.idea/gradle.xml new file mode 100644 index 0000000..8d2df47 --- /dev/null +++ b/ShowCaseApplication/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/libraries/appcompat_v7_22_1_1.xml b/ShowCaseApplication/.idea/libraries/appcompat_v7_22_1_1.xml new file mode 100644 index 0000000..e7e38b5 --- /dev/null +++ b/ShowCaseApplication/.idea/libraries/appcompat_v7_22_1_1.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/libraries/library_aar_1_0_0.xml b/ShowCaseApplication/.idea/libraries/library_aar_1_0_0.xml new file mode 100644 index 0000000..4d2d286 --- /dev/null +++ b/ShowCaseApplication/.idea/libraries/library_aar_1_0_0.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/libraries/support_annotations_22_1_1.xml b/ShowCaseApplication/.idea/libraries/support_annotations_22_1_1.xml new file mode 100644 index 0000000..729886b --- /dev/null +++ b/ShowCaseApplication/.idea/libraries/support_annotations_22_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/libraries/support_v4_22_1_1.xml b/ShowCaseApplication/.idea/libraries/support_v4_22_1_1.xml new file mode 100644 index 0000000..1288311 --- /dev/null +++ b/ShowCaseApplication/.idea/libraries/support_v4_22_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/misc.xml b/ShowCaseApplication/.idea/misc.xml new file mode 100644 index 0000000..e284b1d --- /dev/null +++ b/ShowCaseApplication/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/modules.xml b/ShowCaseApplication/.idea/modules.xml new file mode 100644 index 0000000..98938cb --- /dev/null +++ b/ShowCaseApplication/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/vcs.xml b/ShowCaseApplication/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/ShowCaseApplication/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/.idea/workspace.xml b/ShowCaseApplication/.idea/workspace.xml new file mode 100644 index 0000000..80de07e --- /dev/null +++ b/ShowCaseApplication/.idea/workspace.xml @@ -0,0 +1,2164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + C:\Users\Afzaal\AppData\Roaming\Subversion + + + + + 1453453635828 + + + 1453462814105 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/ShowCaseApplication.iml b/ShowCaseApplication/ShowCaseApplication.iml new file mode 100644 index 0000000..7575ae6 --- /dev/null +++ b/ShowCaseApplication/ShowCaseApplication.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/app/.gitignore b/ShowCaseApplication/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/ShowCaseApplication/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/ShowCaseApplication/app/app.iml b/ShowCaseApplication/app/app.iml new file mode 100644 index 0000000..7322b44 --- /dev/null +++ b/ShowCaseApplication/app/app.iml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShowCaseApplication/app/build.gradle b/ShowCaseApplication/app/build.gradle new file mode 100644 index 0000000..ed608da --- /dev/null +++ b/ShowCaseApplication/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "com.mi.afzaal.showcaseapplication" + minSdkVersion 15 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:22.1.1' + compile 'com.mcxiaoke.volley:library-aar:1.0.0' +} diff --git a/ShowCaseApplication/app/proguard-rules.pro b/ShowCaseApplication/app/proguard-rules.pro new file mode 100644 index 0000000..89d1b20 --- /dev/null +++ b/ShowCaseApplication/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Afzaal\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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 *; +#} diff --git a/ShowCaseApplication/app/src/androidTest/java/com/mi/afzaal/showcaseapplication/ApplicationTest.java b/ShowCaseApplication/app/src/androidTest/java/com/mi/afzaal/showcaseapplication/ApplicationTest.java new file mode 100644 index 0000000..006bf7a --- /dev/null +++ b/ShowCaseApplication/app/src/androidTest/java/com/mi/afzaal/showcaseapplication/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.mi.afzaal.showcaseapplication; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/ShowCaseApplication/app/src/main/AndroidManifest.xml b/ShowCaseApplication/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6e74dcc --- /dev/null +++ b/ShowCaseApplication/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adapters/DeviceListAdapter.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adapters/DeviceListAdapter.java new file mode 100644 index 0000000..9e25f69 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adapters/DeviceListAdapter.java @@ -0,0 +1,44 @@ +package com.mi.afzaal.adapters; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.mi.afzaal.models.DeviceData; +import com.mi.afzaal.showcaseapplication.R; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public class DeviceListAdapter extends ArrayAdapter { + + private final Activity context; + private final ArrayList devicelist; + + public DeviceListAdapter(Activity context,ArrayList list) + { + super(context, R.layout.device_view,list); + this.context = context; + this.devicelist = list; + } + @Override + public View getView(int position, View view, ViewGroup parent) { + LayoutInflater inflater = context.getLayoutInflater(); + DeviceData devicedata = devicelist.get(position); + View rowView= inflater.inflate(R.layout.device_view, null, true); + ImageView image = (ImageView)rowView.findViewById(R.id.image); + TextView text = (TextView) rowView.findViewById(R.id.text); + if(devicedata.toString() != null) + text.setText(devicedata.toString()); + return rowView; + } +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddDevicePresenterImpl.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddDevicePresenterImpl.java new file mode 100644 index 0000000..d73707b --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddDevicePresenterImpl.java @@ -0,0 +1,54 @@ +package com.mi.afzaal.adddevicedetails; + + +import com.mi.afzaal.models.DeviceData; +import com.mi.afzaal.utility.UtilityClass; + +public class AddDevicePresenterImpl implements IAddDevicePresenter,IAddDeviceListener{ + + IAddDeviceView addDeviceView; + IAddDeviceIntractor addDeviceIntractor; + + + public AddDevicePresenterImpl(IAddDeviceView deviceView) { + this.addDeviceView = deviceView; + this.addDeviceIntractor = new IAddDeviceIntractorImpl(); + } + + + @Override + public void AddData(DeviceData d) { + if(addDeviceView!=null){ + addDeviceView.showProgress(); + } + addDeviceIntractor.addDevice(UtilityClass.URL_ADDDEVICE,d, this); + } + + @Override + public void setNetworkError() { + if(addDeviceView!=null) + addDeviceView.setonError(); + + } + + @Override + public void onsuccess() { + // TODO Auto-generated method stub + if(addDeviceView!=null) + addDeviceView.setonSuccess(); + } + + @Override + public void onError() { + if(addDeviceView!=null) + addDeviceView.setonError(); + } + + + @Override + public void onDestroy() { + addDeviceView = null; + } + + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddNewDevice.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddNewDevice.java new file mode 100644 index 0000000..fd9cb78 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/AddNewDevice.java @@ -0,0 +1,106 @@ +package com.mi.afzaal.adddevicedetails; + + + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ProgressBar; +import android.widget.Toast; + +import com.mi.afzaal.models.DeviceData; +import com.mi.afzaal.showcaseapplication.DevicesListActivity; +import com.mi.afzaal.showcaseapplication.R; + +public class AddNewDevice extends Activity implements IAddDeviceView,OnClickListener{ + + EditText name,version,codename,target,distribution; + Button submit; + ProgressBar progressBar; + AddDevicePresenterImpl devicePresentor; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.addnewdevice_view); + name = (EditText) findViewById(R.id.name); + version = (EditText) findViewById(R.id.version); + codename = (EditText) findViewById(R.id.codename); + target = (EditText) findViewById(R.id.target); + distribution = (EditText) findViewById(R.id.distribution); + progressBar = (ProgressBar) findViewById(R.id.progressBar); + submit = (Button) findViewById(R.id.submit); + submit.setOnClickListener(this); + devicePresentor = new AddDevicePresenterImpl(this); + + } + @Override + public void showProgress() { + progressBar.setVisibility(View.VISIBLE); + } + @Override + public void hideProgress() { + progressBar.setVisibility(View.GONE); + + } + @Override + public void setonSuccess() { + progressBar.setVisibility(View.GONE); + Toast.makeText(getApplicationContext(), "Data Saved Successfully",Toast.LENGTH_SHORT).show(); + this.navigateToHome(); + } + @Override + public void setonError() { + progressBar.setVisibility(View.GONE); + Toast.makeText(getApplicationContext(), "Error in Saving Data",Toast.LENGTH_SHORT).show(); + this.navigateToHome(); + } + @Override + public void onClick(View v) { + + if(v == submit){ + if(Validation()){ + progressBar.setVisibility(View.VISIBLE); + DeviceData data = new DeviceData(); + data.setName(name.getText().toString()); + data.setVersion(version.getText().toString()); + data.setCodename(codename.getText().toString()); + data.setTarget(target.getText().toString()); + + data.setDistribution(distribution.getText().toString()); + devicePresentor.AddData(data); + } + } + } + private boolean Validation(){ + if(TextUtils.isEmpty(name.getText().toString().trim())) { + name.setError("Enter the Name"); + return false; + } else if(TextUtils.isEmpty(version.getText().toString().trim())) { + version.setError("Enter the Version"); + return false; + } else if(TextUtils.isEmpty(codename.getText().toString().trim())) { + codename.setError("Enter the Code name"); + return false; + } else if(TextUtils.isEmpty(target.getText().toString().trim())) { + target.setError("Enter the Target"); + return false; + } else if(TextUtils.isEmpty(distribution.getText().toString().trim())) { + distribution.setError("Enter the Distribution"); + return false; + } + return true; + } + @Override + public void navigateToHome() { + Intent i =new Intent(AddNewDevice.this,DevicesListActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK); + finish(); + startActivity(i); + } + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractor.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractor.java new file mode 100644 index 0000000..a03421a --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractor.java @@ -0,0 +1,10 @@ +package com.mi.afzaal.adddevicedetails; + + +import com.mi.afzaal.models.DeviceData; + +public interface IAddDeviceIntractor { + + void addDevice(String url, DeviceData data, IAddDeviceListener listener); + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractorImpl.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractorImpl.java new file mode 100644 index 0000000..2342eca --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceIntractorImpl.java @@ -0,0 +1,54 @@ +package com.mi.afzaal.adddevicedetails; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.toolbox.JsonObjectRequest; +import com.mi.afzaal.models.DeviceData; +import com.mi.afzaal.showcaseapplication.AppController; + +public class IAddDeviceIntractorImpl implements IAddDeviceIntractor{ + + @Override + public void addDevice(String url, DeviceData data, + final IAddDeviceListener listener) { + + JSONObject dataobj = createJsonObject(data); + JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, url,dataobj , + new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + if(response !=null){ + listener.onsuccess(); + + } + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + listener.onError(); + listener.setNetworkError(); + } + }); + + AppController.getInstance().addToRequestQueue(jsObjRequest); + } + + JSONObject createJsonObject(DeviceData data){ + JSONObject jObj = new JSONObject(); + try{ + jObj.put("name", data.getName()); + jObj.put("version", data.getVersion()); + jObj.put("codename", data.getCodename()); + jObj.put("target", data.getTarget()); + jObj.put("distribution", data.getDistribution()); + }catch(JSONException ex){ + + } + return jObj; + } + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceListener.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceListener.java new file mode 100644 index 0000000..4fa422c --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceListener.java @@ -0,0 +1,7 @@ +package com.mi.afzaal.adddevicedetails; + +public interface IAddDeviceListener { + void setNetworkError(); + void onsuccess(); + void onError(); +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDevicePresenter.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDevicePresenter.java new file mode 100644 index 0000000..67686d2 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDevicePresenter.java @@ -0,0 +1,10 @@ +package com.mi.afzaal.adddevicedetails; + + +import com.mi.afzaal.models.DeviceData; + +public interface IAddDevicePresenter { + + void AddData(DeviceData d); + void onDestroy(); +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceView.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceView.java new file mode 100644 index 0000000..79ddba8 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/adddevicedetails/IAddDeviceView.java @@ -0,0 +1,11 @@ +package com.mi.afzaal.adddevicedetails; + +public interface IAddDeviceView { + + void showProgress(); + void hideProgress(); + void setonSuccess(); + void setonError(); + void navigateToHome(); + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/databasehelper/DatabaseHandler.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/databasehelper/DatabaseHandler.java new file mode 100644 index 0000000..f68447d --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/databasehelper/DatabaseHandler.java @@ -0,0 +1,91 @@ +package com.mi.afzaal.databasehelper; + + +import java.util.ArrayList; + +import android.content.ContentValues; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +import com.mi.afzaal.models.DeviceData; + + +public class DatabaseHandler extends SQLiteOpenHelper { + + // All Static variables + // Database Version + private static final int DATABASE_VERSION = 1; + + // Database Name + private static final String DATABASE_NAME = "deviceinfo"; + + // Contacts table name + private static final String TABLE_DEVICE = "devices"; + + // Contacts Table Columns names + private static final String KEY_ID = "id"; + private static final String KEY_NAME = "name"; + private static final String KEY_VERSION = "version"; + private static final String KEY_CODENAME = "codename"; + private static final String KEY_TARGET = "target"; + private static final String KEY_DISTRIBUTION="distribution"; + + + + + public DatabaseHandler(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + // Creating Tables + @Override + public void onCreate(SQLiteDatabase db) { + String CREATE_DEVICE_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_DEVICE + "(" + + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME + " TEXT," + KEY_VERSION + " TEXT," + + KEY_CODENAME + " TEXT," + KEY_TARGET + " TEXT,"+ KEY_DISTRIBUTION +" TEXT" + + ")"; + + + + db.execSQL(CREATE_DEVICE_TABLE); + + } + + // Upgrading database + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // Drop older table if existed + db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEVICE); + // Create tables again + onCreate(db); + } + + + // Adding new contact + public void addContact(ArrayList devicedata) { + + SQLiteDatabase db = this.getWritableDatabase(); + + for(int i =0;i void addToRequestQueue(Request req, String tag) { + // set the default tag if tag is empty + req.setTag(TextUtils.isEmpty(tag) ? TAG : tag); + getRequestQueue().add(req); + } + + public void addToRequestQueue(Request req) { + req.setTag(TAG); + getRequestQueue().add(req); + } + + public void cancelPendingRequests(Object tag) { + if (mRequestQueue != null) { + mRequestQueue.cancelAll(tag); + } + } +} \ No newline at end of file diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DeviceListPresenterImpl.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DeviceListPresenterImpl.java new file mode 100644 index 0000000..5f9767c --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DeviceListPresenterImpl.java @@ -0,0 +1,64 @@ +package com.mi.afzaal.showcaseapplication; + +import java.util.ArrayList; +import java.util.List; + +import android.content.Context; + +import com.mi.afzaal.models.DeviceData; +import com.mi.afzaal.utility.UtilityClass; + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public class DeviceListPresenterImpl implements iDeviceListPresenter,OnDataReceivedListener { + iDeviceListView deviceView; + IDeviceListIntractor deviceInteractor; + + public DeviceListPresenterImpl(iDeviceListView deviceView) { + this.deviceView = deviceView; + this.deviceInteractor = new IDeviceListInteractorImpl(); + } + + + @Override + public ArrayList getData() { + if(deviceView!=null){ + deviceView.showProgress(); + } + return deviceInteractor.getDeviceList(UtilityClass.URL_DEVICELIST,this); + } + + @Override + public void onDestroy() { + deviceView = null; + } + + @Override + public void setNetworkError() { + if(deviceView!=null) + deviceView.setonError(); + } + + @Override + public void onsuccess() { + + } + + @Override + public void setData(ArrayList devicedata) { + if(deviceView != null) + deviceView.setData(devicedata); + } + + + @Override + public void saveDataToDB(Context c,ArrayList data) { + if(deviceView !=null){ + deviceInteractor.saveToDb(c,data); + } + } + + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DevicesListActivity.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DevicesListActivity.java new file mode 100644 index 0000000..3c28d3e --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/DevicesListActivity.java @@ -0,0 +1,88 @@ +package com.mi.afzaal.showcaseapplication; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.ProgressBar; +import android.widget.RelativeLayout; + +import com.mi.afzaal.adapters.DeviceListAdapter; +import com.mi.afzaal.adddevicedetails.AddNewDevice; +import com.mi.afzaal.models.DeviceData; + +import java.util.ArrayList; +import java.util.List; + +public class DevicesListActivity extends Activity implements iDeviceListView,OnClickListener { + + ListView devicesList; + DeviceListPresenterImpl deviceListPresenter; + RelativeLayout progressview; + ProgressBar progressbar; + ImageView AddDevice; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_devices_list); + devicesList = (ListView)findViewById(R.id.devicesList); + progressview = (RelativeLayout)findViewById(R.id.progressview); + progressbar = (ProgressBar)findViewById(R.id.progressbar); + AddDevice = (ImageView) findViewById(R.id.AddDevice); + AddDevice.setOnClickListener(this); + deviceListPresenter = new DeviceListPresenterImpl(this); + deviceListPresenter.getData(); + } + + + @Override + public void showProgress() { + progressbar.setVisibility(View.VISIBLE); + } + + @Override + public void hideProgress() { + progressbar.setVisibility(View.GONE); + progressview.setVisibility(View.GONE); + } + + @Override + public void setData(ArrayList dataList) { + if(dataList!=null) { + progressbar.setVisibility(View.GONE); + progressview.setVisibility(View.GONE); + deviceListPresenter.saveDataToDB(getApplicationContext(), dataList); + DeviceListAdapter adapter = new DeviceListAdapter(DevicesListActivity.this, dataList); + devicesList.setAdapter(adapter); + } + } + + @Override + public void setonError() { + progressbar.setVisibility(View.GONE); + progressview.setVisibility(View.GONE); + } + + @Override + public void setonSuccess() { + progressbar.setVisibility(View.GONE); + progressview.setVisibility(View.GONE); + } + + @Override + public void savetoDB(ArrayList list) { + + } + + + @Override + public void onClick(View v) { + if(v==AddDevice){ + startActivity(new Intent(DevicesListActivity.this,AddNewDevice.class)); + } + } +} + diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/IDeviceListInteractorImpl.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/IDeviceListInteractorImpl.java new file mode 100644 index 0000000..a38a429 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/IDeviceListInteractorImpl.java @@ -0,0 +1,148 @@ +package com.mi.afzaal.showcaseapplication; + +import android.content.Context; +import android.util.Log; + +import com.android.volley.Request; +import com.android.volley.Response; +import com.android.volley.VolleyError; +import com.android.volley.VolleyLog; +import com.android.volley.toolbox.JsonArrayRequest; +import com.android.volley.toolbox.JsonObjectRequest; +import com.android.volley.toolbox.StringRequest; +import com.mi.afzaal.databasehelper.DatabaseHandler; +import com.mi.afzaal.models.DeviceData; + + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public class IDeviceListInteractorImpl implements IDeviceListIntractor { + + ArrayList deviceData; + + @Override + public ArrayList getDeviceList(String url, final OnDataReceivedListener listener) { + + StringRequest jsObjRequest = new StringRequest(Request.Method.GET, + url, new Response.Listener() { + + @Override + public void onResponse(String response) { + Log.d("VOLLEY", response.toString()); + deviceData= getResponse(response); + + listener.onsuccess(); + listener.setData(deviceData); + + } + }, new Response.ErrorListener() { + + @Override + public void onErrorResponse(VolleyError error) { + VolleyLog.d("VOLLEY", "Error: " + error.getMessage()); + deviceData = null; + listener.setNetworkError(); + } + }); + + + AppController.getInstance().addToRequestQueue(jsObjRequest); + return deviceData; + + } + + @Override + public void saveToDb(Context c,ArrayList devicelist) { + DatabaseHandler dbHandler = new DatabaseHandler(c); + dbHandler.addContact(devicelist); + + } + + ArrayList getResponse(String response){ + ArrayList data = new ArrayList(); + JSONArray CatjArray = null; + try { + CatjArray = new JSONArray(response); + } catch (JSONException e) { + e.printStackTrace(); + } + JSONObject cat_json_data=null; + for(int i=0;i getDeviceList(String url, OnDataReceivedListener listener); + void saveToDb(Context c, ArrayList devicelist); +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/OnDataReceivedListener.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/OnDataReceivedListener.java new file mode 100644 index 0000000..878470f --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/OnDataReceivedListener.java @@ -0,0 +1,19 @@ +package com.mi.afzaal.showcaseapplication; + + +import com.mi.afzaal.models.DeviceData; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public interface OnDataReceivedListener { + + void setNetworkError(); + void onsuccess(); + void setData(ArrayList devicedata); +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListPresenter.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListPresenter.java new file mode 100644 index 0000000..f931fec --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListPresenter.java @@ -0,0 +1,19 @@ +package com.mi.afzaal.showcaseapplication; + +import java.util.ArrayList; +import java.util.List; + +import android.content.Context; + +import com.mi.afzaal.models.DeviceData; + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public interface iDeviceListPresenter { + ArrayList getData(); + void saveDataToDB(Context c, ArrayList data); + void onDestroy(); + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListView.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListView.java new file mode 100644 index 0000000..81dec46 --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/showcaseapplication/iDeviceListView.java @@ -0,0 +1,22 @@ +package com.mi.afzaal.showcaseapplication; + +import com.mi.afzaal.models.DeviceData; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * Created by F ABBASI on 1/21/2016. + */ +public interface iDeviceListView { + + void showProgress(); + void hideProgress(); + void setData(ArrayList dataList); + void setonError(); + void setonSuccess(); + void savetoDB(ArrayList list); + +} diff --git a/ShowCaseApplication/app/src/main/java/com/mi/afzaal/utility/UtilityClass.java b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/utility/UtilityClass.java new file mode 100644 index 0000000..0f6b79a --- /dev/null +++ b/ShowCaseApplication/app/src/main/java/com/mi/afzaal/utility/UtilityClass.java @@ -0,0 +1,9 @@ +package com.mi.afzaal.utility; + +/** + * Created by F ABBASI on 1/21/2016. + */ +public class UtilityClass { + public static String URL_DEVICELIST = "http://mobilesandboxdev.azurewebsites.net/android/"; + public static String URL_ADDDEVICE = "http://mobilesandboxdev.azurewebsites.net/android"; +} diff --git a/ShowCaseApplication/app/src/main/res/drawable/ic_launcher.png b/ShowCaseApplication/app/src/main/res/drawable/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/ShowCaseApplication/app/src/main/res/drawable/ic_launcher.png differ diff --git a/ShowCaseApplication/app/src/main/res/drawable/plussign.png b/ShowCaseApplication/app/src/main/res/drawable/plussign.png new file mode 100644 index 0000000..6aa5bd8 Binary files /dev/null and b/ShowCaseApplication/app/src/main/res/drawable/plussign.png differ diff --git a/ShowCaseApplication/app/src/main/res/drawable/textfield_shape.xml b/ShowCaseApplication/app/src/main/res/drawable/textfield_shape.xml new file mode 100644 index 0000000..6f86572 --- /dev/null +++ b/ShowCaseApplication/app/src/main/res/drawable/textfield_shape.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/ShowCaseApplication/app/src/main/res/layout/activity_devices_list.xml b/ShowCaseApplication/app/src/main/res/layout/activity_devices_list.xml new file mode 100644 index 0000000..571b2a3 --- /dev/null +++ b/ShowCaseApplication/app/src/main/res/layout/activity_devices_list.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + diff --git a/ShowCaseApplication/app/src/main/res/layout/addnewdevice_view.xml b/ShowCaseApplication/app/src/main/res/layout/addnewdevice_view.xml new file mode 100644 index 0000000..b3555c9 --- /dev/null +++ b/ShowCaseApplication/app/src/main/res/layout/addnewdevice_view.xml @@ -0,0 +1,77 @@ + + + + + + + + + +