Commit 6913b966 authored by DESKTOP-NFGF3PG\zxa01's avatar DESKTOP-NFGF3PG\zxa01

commit detail and privacy of device

parent b010ef94
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
...@@ -32,14 +32,21 @@ dependencies { ...@@ -32,14 +32,21 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation "com.squareup.retrofit2:retrofit:2.1.0"
implementation "com.squareup.retrofit2:converter-gson:2.1.0"
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// rxjava
implementation "io.reactivex:rxjava:1.1.8"
implementation "io.reactivex:rxandroid:1.2.1"
// retrofit2
implementation "com.squareup.retrofit2:retrofit:2.1.0"
implementation "com.squareup.retrofit2:converter-gson:2.1.0"
// 可移除 // 可移除
implementation 'com.squareup.okhttp3:okhttp:3.14.1' implementation 'com.squareup.okhttp3:okhttp:3.14.1'
implementation 'com.jakewharton:butterknife:9.0.0-rc2' implementation 'com.jakewharton:butterknife:9.0.0-rc2'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2' annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
implementation 'com.android.support:gridlayout-v7:28.0.0'
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zxa01.iotclient"> package="com.example.zxa01.iotclient">
<!-- To auto-complete the email text field in the login form with the user's emails --> <!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.READ_PROFILE" />
...@@ -17,24 +16,31 @@ ...@@ -17,24 +16,31 @@
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".login.LoginActivity" android:name=".login.view.LoginActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan">
>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".home.HomeActivity" android:name=".home.HomeActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" android:windowSoftInputMode="adjustPan" />
></activity>
<activity
android:name=".detail.view.DetailActivity"
android:label="@string/title_detail"
android:screenOrientation="portrait"></activity>
<activity
android:name=".privacy.PrivacyActivity"
android:label="@string/title_privacy"
android:screenOrientation="portrait" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.example.zxa01.iotclient.bindings; package com.example.zxa01.iotclient.common.bindings;
import android.databinding.BindingAdapter; import android.databinding.BindingAdapter;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
......
package com.example.zxa01.iotclient.http; package com.example.zxa01.iotclient.common.http;
import com.example.zxa01.iotclient.home.device.model.DeviceModel;
import com.example.zxa01.iotclient.home.device.model.DevicesModel;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -11,6 +9,7 @@ import retrofit2.Call; ...@@ -11,6 +9,7 @@ import retrofit2.Call;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST;
public class Api { public class Api {
...@@ -38,6 +37,10 @@ public class Api { ...@@ -38,6 +37,10 @@ public class Api {
public interface ApiInterface { public interface ApiInterface {
@GET("/api/breeds/list/all") @GET("/api/breeds/list/all")
Call<Object> getDevices(); Call<Object> getDevices();
@POST("/api/breeds/list/all")
Call<Object> login();
// @GET("/api/breed/{breed}/images") // @GET("/api/breed/{breed}/images")
// Call<DogBreedImages> getImagesByBreed(@Path("breed") String breed); // Call<DogBreedImages> getImagesByBreed(@Path("breed") String breed);
......
package com.example.zxa01.iotclient.http; package com.example.zxa01.iotclient.common.http;
import java.io.IOException; import java.io.IOException;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
......
package com.example.zxa01.iotclient.pojo; package com.example.zxa01.iotclient.common.pojo;
public class Setting { public class Setting {
private String key; private String key;
......
package com.example.zxa01.iotclient.detail.model;
import android.databinding.BaseObservable;
public class DetailModel extends BaseObservable {
}
package com.example.zxa01.iotclient.detail.view;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toolbar;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.ActivityDetailBinding;
public class DetailActivity extends AppCompatActivity {
private ActivityDetailBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_detail);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
}
package com.example.zxa01.iotclient.home; package com.example.zxa01.iotclient.home;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.ActivityHomeBinding;
import com.example.zxa01.iotclient.home.device.view.DeviceFragment;
import com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel;
import com.example.zxa01.iotclient.home.record.RecordFragment;
import com.example.zxa01.iotclient.home.setting.SettingFragment;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import com.example.zxa01.iotclient.R; import android.databinding.DataBindingUtil;
import com.example.zxa01.iotclient.databinding.ActivityHomeBinding;
import com.example.zxa01.iotclient.home.device.view.DeviceFragment;
import com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel;
import com.example.zxa01.iotclient.home.privacy.PrivacyFragment;
import com.example.zxa01.iotclient.home.setting.SettingFragment;
public class HomeActivity extends AppCompatActivity implements public class HomeActivity extends AppCompatActivity implements
DeviceFragment.OnFragmentInteractionListener, DeviceFragment.OnFragmentInteractionListener,
PrivacyFragment.OnFragmentInteractionListener, RecordFragment.OnFragmentInteractionListener,
SettingFragment.OnFragmentInteractionListener { SettingFragment.OnFragmentInteractionListener {
/* data binding */
private ActivityHomeBinding binding; private ActivityHomeBinding binding;
/* fragments of HomeActivity */ /* fragments of HomeActivity */
private DeviceFragment mDeviceFragment = new DeviceFragment(); private DeviceFragment mDeviceFragment = new DeviceFragment();
private PrivacyFragment mPrivacyFragment = new PrivacyFragment(); private RecordFragment mRecordFragment = new RecordFragment();
private SettingFragment mSettingFragment = new SettingFragment(); private SettingFragment mSettingFragment = new SettingFragment();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this,R.layout.activity_home); binding = DataBindingUtil.setContentView(this, R.layout.activity_home);
/* init */
setupFragment(binding.navigation); setupFragment(binding.navigation);
showFragment(mDeviceFragment); showFragment(mDeviceFragment);
} }
...@@ -51,7 +50,7 @@ public class HomeActivity extends AppCompatActivity implements ...@@ -51,7 +50,7 @@ public class HomeActivity extends AppCompatActivity implements
} }
/* onItemSelected of fragment */ /* onItemSelected of fragment */
private void setupFragment(BottomNavigationView view){ private void setupFragment(BottomNavigationView view) {
view.setOnNavigationItemSelectedListener( view.setOnNavigationItemSelectedListener(
menuItem -> { menuItem -> {
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
...@@ -59,7 +58,7 @@ public class HomeActivity extends AppCompatActivity implements ...@@ -59,7 +58,7 @@ public class HomeActivity extends AppCompatActivity implements
showFragment(mDeviceFragment); showFragment(mDeviceFragment);
return true; return true;
case R.id.navigation_privacy: case R.id.navigation_privacy:
showFragment(mPrivacyFragment); showFragment(mRecordFragment);
return true; return true;
case R.id.navigation_setting: case R.id.navigation_setting:
showFragment(mSettingFragment); showFragment(mSettingFragment);
...@@ -80,10 +79,12 @@ public class HomeActivity extends AppCompatActivity implements ...@@ -80,10 +79,12 @@ public class HomeActivity extends AppCompatActivity implements
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) { public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
new DevicesViewModel().createDevice(intent.getStringExtra("SCAN_RESULT")); new DeviceViewModel().createDevice(intent.getStringExtra("SCAN_RESULT"));
} } else {
new AlertDialog.Builder(this)
.setMessage(R.string.qrcode_error)
.show();
} }
} }
} }
package com.example.zxa01.iotclient.home.device.model; package com.example.zxa01.iotclient.home.device.model;
import com.example.zxa01.iotclient.pojo.Device;
import com.example.zxa01.iotclient.common.http.Api;
import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.common.pojo.device.Manufacturer;
import com.example.zxa01.iotclient.common.pojo.device.Model;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable; import android.databinding.BaseObservable;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DeviceModel extends BaseObservable { public class DeviceModel extends BaseObservable {
private Device device; private String status;
private List<Device> deviceList;
private MutableLiveData<List<Device>> devices;
// fake
private Device oxygenDevice = new Device()
.setUDN("a1252c49-4188-4e6d-a32e-66604c664fb8")
.setName("指尖式血氧機")
.setType(Device.Type.Sensor)
.setManufacturer(new Manufacturer()
.setName("Facelake")
.setSerialNumber("3176927193")
.setUrl("http://facelake.com"))
.setModel(new Model()
.setName("指尖式血氧機")
.setDescription("本設備是為符合不同領域及照護應用而設計,並把這些特色融入小如指節的分析儀中,可在數秒內量測出準確可靠的血氧及心跳值。")
.setUrl("https://www.amazon.com/Pulse-Oximeter-Blood-Oxygen-Monitor/dp/B00HXXO332"))
.setUPC("B00HXXO332")
.setLocation("25.013068, 121.541651")
.setStatus(Device.Status.Disconnected);
public DeviceModel(Device device){
this.device = device; public DeviceModel() {
deviceList = new ArrayList<>();
devices = new MutableLiveData<>();
} }
public Device getDevice() { public void addDevice(Device device) {
return device; deviceList.add(device);
} }
public void setDevice(Device device) { public MutableLiveData<List<Device>> getDevices() {
this.device = device; return devices;
}
public void fetchDevices() {
Callback<Object> callback = new Callback<Object>() {
@Override
public void onResponse(Call<Object> call, Response<Object> response) {
// TODO transfer response
Log.i("Test", response.message());
DeviceModel deviceModel = new DeviceModel();
deviceModel.addDevice(oxygenDevice);
deviceModel.addDevice(oxygenDevice);
devices.setValue(deviceModel.deviceList);
status = "success";
}
@Override
public void onFailure(Call<Object> call, Throwable t) {
Log.e("fetchDevices - onFailure()", t.getMessage(), t);
}
};
Api.getApi().getDevices().enqueue(callback);
}
public void createDevice(String address) {
// TODO api post-createDevice & update
}
public String getStatus() {
return status;
} }
}
public void setStatus(String statue) {
this.status = statue;
}
}
package com.example.zxa01.iotclient.home.device.model;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import android.util.Log;
import com.example.zxa01.iotclient.http.Api;
import com.example.zxa01.iotclient.pojo.Device;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class DevicesModel extends BaseObservable {
private String status;
private List<DeviceModel> deviceList = new ArrayList<>();
private MutableLiveData<List<DeviceModel>> devices = new MutableLiveData<>();
public void addDevice(DeviceModel device) {
deviceList.add(device);
}
public MutableLiveData<List<DeviceModel>> getDevices() {
return devices;
}
public void fetchDevices() {
Callback<Object> callback = new Callback<Object>() {
@Override
public void onResponse(Call<Object> call, Response<Object> response) {
// TODO transfer response
Log.i("Test", response.message());
DevicesModel devicesModel = new DevicesModel();
devicesModel.addDevice(new DeviceModel(
new Device(1, "test", "test", "test", true)));
devices.setValue(devicesModel.deviceList);
status = "success";
}
@Override
public void onFailure(Call<Object> call, Throwable t) {
Log.e("Test", t.getMessage(), t);
}
};
Api.getApi().getDevices().enqueue(callback);
}
public void createDevice(String address) {
// TODO api post-createDevice & update
}
public String getStatus() {
return status;
}
public void setStatus(String statue) {
this.status = statue;
}
}
...@@ -9,18 +9,18 @@ import android.view.LayoutInflater; ...@@ -9,18 +9,18 @@ import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.example.zxa01.iotclient.BR; import com.example.zxa01.iotclient.BR;
import com.example.zxa01.iotclient.home.device.model.DeviceModel; import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel; import com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel;
import java.util.List; import java.util.List;
public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHolder> { public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHolder> {
private int layoutId; private int layoutId;
private List<DeviceModel> deviceList; private List<Device> deviceList;
private DevicesViewModel viewModel; private DeviceViewModel viewModel;
public DeviceAdapter(@LayoutRes int layoutId, DevicesViewModel viewModel) { public DeviceAdapter(@LayoutRes int layoutId, DeviceViewModel viewModel) {
this.layoutId = layoutId; this.layoutId = layoutId;
this.viewModel = viewModel; this.viewModel = viewModel;
} }
...@@ -50,7 +50,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold ...@@ -50,7 +50,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold
return getLayoutIdForPosition(position); return getLayoutIdForPosition(position);
} }
public void setDevices(List<DeviceModel> deviceList) { public void setDevices(List<Device> deviceList) {
this.deviceList = deviceList; this.deviceList = deviceList;
} }
...@@ -63,7 +63,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold ...@@ -63,7 +63,7 @@ public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.MyViewHold
this.binding = binding; this.binding = binding;
} }
void bind(DevicesViewModel viewModel, Integer position) { void bind(DeviceViewModel viewModel, Integer position) {
viewModel.getDeviceAt(position); viewModel.getDeviceAt(position);
binding.setVariable(BR.viewModel, viewModel); binding.setVariable(BR.viewModel, viewModel);
binding.setVariable(BR.position, position); binding.setVariable(BR.position, position);
......
...@@ -10,15 +10,16 @@ import android.support.v7.widget.LinearLayoutManager; ...@@ -10,15 +10,16 @@ import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceBinding; import com.example.zxa01.iotclient.databinding.FragmentDeviceBinding;
import com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel; import com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel;
import com.example.zxa01.iotclient.home.device.view.create.DeviceCreateFragment; import com.example.zxa01.iotclient.home.device.view.create.DeviceCreateFragment;
public class DeviceFragment extends Fragment { public class DeviceFragment extends Fragment {
private FragmentDeviceBinding binding; private FragmentDeviceBinding binding;
private DevicesViewModel viewModel = new DevicesViewModel(); private DeviceViewModel viewModel;
public DeviceFragment() { public DeviceFragment() {
} }
...@@ -31,8 +32,11 @@ public class DeviceFragment extends Fragment { ...@@ -31,8 +32,11 @@ public class DeviceFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_device, container, false); binding = DataBindingUtil.inflate(inflater, R.layout.fragment_device, container, false);
viewModel = new DeviceViewModel(binding.getRoot().getContext());
binding.setViewModel(viewModel); binding.setViewModel(viewModel);
setup(); binding.fab.setOnClickListener(item -> drawDialog());
binding.deviceRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
init();
return binding.getRoot(); return binding.getRoot();
} }
...@@ -46,9 +50,7 @@ public class DeviceFragment extends Fragment { ...@@ -46,9 +50,7 @@ public class DeviceFragment extends Fragment {
super.onDetach(); super.onDetach();
} }
private void setup() { private void init() {
binding.fab.setOnClickListener(item -> drawDialog());
binding.deviceRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
viewModel.refreshDevices(); viewModel.refreshDevices();
viewModel.getDevices().observe(this, deviceList -> viewModel.setAdapter(deviceList)); viewModel.getDevices().observe(this, deviceList -> viewModel.setAdapter(deviceList));
} }
...@@ -63,6 +65,7 @@ public class DeviceFragment extends Fragment { ...@@ -63,6 +65,7 @@ public class DeviceFragment extends Fragment {
new DeviceCreateFragment().show(fragmentTransaction, String.valueOf(R.string.dialog)); new DeviceCreateFragment().show(fragmentTransaction, String.valueOf(R.string.dialog));
} }
public interface OnFragmentInteractionListener { public interface OnFragmentInteractionListener {
void onDeviceFragment(Uri uri); void onDeviceFragment(Uri uri);
} }
......
...@@ -13,7 +13,7 @@ import android.view.ViewGroup; ...@@ -13,7 +13,7 @@ import android.view.ViewGroup;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.FragmentDeviceCreateBinding; import com.example.zxa01.iotclient.databinding.FragmentDeviceCreateBinding;
import com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel; import com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel;
public class DeviceCreateFragment extends DialogFragment { public class DeviceCreateFragment extends DialogFragment {
...@@ -34,14 +34,10 @@ public class DeviceCreateFragment extends DialogFragment { ...@@ -34,14 +34,10 @@ public class DeviceCreateFragment extends DialogFragment {
return new AlertDialog.Builder(getActivity()) return new AlertDialog.Builder(getActivity())
.setView(R.layout.fragment_device_create) .setView(R.layout.fragment_device_create)
.setNeutralButton(R.string.button_qrcode, .setNeutralButton(R.string.button_qrcode,
(dialog, whichButton) -> { (dialog, whichButton) -> qrcodeIntent()
qrcodeIntent();
}
) )
.setPositiveButton(R.string.button_correct, .setPositiveButton(R.string.button_correct,
(dialog, whichButton) -> { (dialog, whichButton) -> new DeviceViewModel().createDevice("address")
new DevicesViewModel().createDevice("address");
}
) )
.setNegativeButton(R.string.button_cancel, (dialog, whichButton) -> { .setNegativeButton(R.string.button_cancel, (dialog, whichButton) -> {
}) })
......
package com.example.zxa01.iotclient.home.device.viewModel; package com.example.zxa01.iotclient.home.device.viewModel;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.home.device.model.DeviceModel; import com.example.zxa01.iotclient.common.pojo.device.Device;
import com.example.zxa01.iotclient.detail.view.DetailActivity;
import com.example.zxa01.iotclient.home.device.view.DeviceAdapter; import com.example.zxa01.iotclient.home.device.view.DeviceAdapter;
import com.example.zxa01.iotclient.home.device.model.DevicesModel; import com.example.zxa01.iotclient.home.device.model.DeviceModel;
import com.example.zxa01.iotclient.pojo.Device;
import android.arch.lifecycle.MutableLiveData; import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel; import android.arch.lifecycle.ViewModel;
import android.databinding.ObservableArrayList; import android.content.Context;
import android.content.Intent;
import android.databinding.ObservableBoolean; import android.databinding.ObservableBoolean;
import android.databinding.ObservableList;
import android.util.Log;
import java.util.List; import java.util.List;
import retrofit2.Call; public class DeviceViewModel extends ViewModel {
import retrofit2.Response;
public class DevicesViewModel extends ViewModel {
public ObservableList<Device> mDevices = new ObservableArrayList<>(); public ObservableBoolean isLoading = new ObservableBoolean(true);
public ObservableBoolean isLoading = new ObservableBoolean(false); private Context context;
private DevicesModel devicesModel = new DevicesModel(); private DeviceModel deviceModel = new DeviceModel();
private DeviceAdapter adapter = new DeviceAdapter(R.layout.recycler_view_device, this); private DeviceAdapter adapter = new DeviceAdapter(R.layout.recycler_view_device, this);
public DeviceViewModel(Context context) {
this.context = context;
}
public DeviceViewModel() {
}
/** /**
* model * model
*/ */
public void refreshDevices() { public void refreshDevices() {
devicesModel.fetchDevices(); deviceModel.fetchDevices();
} }
public MutableLiveData<List<DeviceModel>> getDevices() { public MutableLiveData<List<Device>> getDevices() {
return devicesModel.getDevices(); return deviceModel.getDevices();
} }
public void createDevice(String address) { public void createDevice(String address) {
devicesModel.createDevice(address); deviceModel.createDevice(address);
this.refreshDevices(); this.refreshDevices();
} }
...@@ -46,15 +51,26 @@ public class DevicesViewModel extends ViewModel { ...@@ -46,15 +51,26 @@ public class DevicesViewModel extends ViewModel {
* child model * child model
*/ */
public DeviceModel getDeviceAt(Integer index) { public Device getDeviceAt(Integer index) {
if (devicesModel.getDevices().getValue() != null && if (deviceModel.getDevices().getValue() != null &&
index != null && index != null &&
devicesModel.getDevices().getValue().size() > index) { deviceModel.getDevices().getValue().size() > index) {
return devicesModel.getDevices().getValue().get(index); return deviceModel.getDevices().getValue().get(index);
} }
return null; return null;
} }
public void onDevicesClick(Integer index) {
if (deviceModel.getDevices().getValue() != null &&
index != null &&
deviceModel.getDevices().getValue().size() > index) {
// TODO detail of device
context.startActivity(
new Intent(context, DetailActivity.class)
.putExtra("index", index));
}
}
/** /**
* adapter * adapter
*/ */
...@@ -63,7 +79,8 @@ public class DevicesViewModel extends ViewModel { ...@@ -63,7 +79,8 @@ public class DevicesViewModel extends ViewModel {
return adapter; return adapter;
} }
public void setAdapter(List<DeviceModel> deviceList) { public void setAdapter(List<Device> deviceList) {
this.isLoading.set(false);
this.adapter.setDevices(deviceList); this.adapter.setDevices(deviceList);
this.adapter.notifyDataSetChanged(); this.adapter.notifyDataSetChanged();
} }
......
package com.example.zxa01.iotclient.home.privacy; package com.example.zxa01.iotclient.home.record;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
...@@ -13,12 +13,12 @@ import com.example.zxa01.iotclient.R; ...@@ -13,12 +13,12 @@ import com.example.zxa01.iotclient.R;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the * Activities that contain this fragment must implement the
* {@link PrivacyFragment.OnFragmentInteractionListener} interface * {@link RecordFragment.OnFragmentInteractionListener} interface
* to handle interaction events. * to handle interaction events.
* Use the {@link PrivacyFragment#newInstance} factory method to * Use the {@link RecordFragment#newInstance} factory method to
* create an instance of this fragment. * create an instance of this fragment.
*/ */
public class PrivacyFragment extends Fragment { public class RecordFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
...@@ -30,7 +30,7 @@ public class PrivacyFragment extends Fragment { ...@@ -30,7 +30,7 @@ public class PrivacyFragment extends Fragment {
private OnFragmentInteractionListener mListener; private OnFragmentInteractionListener mListener;
public PrivacyFragment() { public RecordFragment() {
// Required empty public constructor // Required empty public constructor
} }
...@@ -43,8 +43,8 @@ public class PrivacyFragment extends Fragment { ...@@ -43,8 +43,8 @@ public class PrivacyFragment extends Fragment {
* @return A new instance of fragment PrivacyFragment. * @return A new instance of fragment PrivacyFragment.
*/ */
// TODO: Rename and change types and number of parameters // TODO: Rename and change types and number of parameters
public static PrivacyFragment newInstance(String param1, String param2) { public static RecordFragment newInstance(String param1, String param2) {
PrivacyFragment fragment = new PrivacyFragment(); RecordFragment fragment = new RecordFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1); args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2); args.putString(ARG_PARAM2, param2);
...@@ -65,7 +65,7 @@ public class PrivacyFragment extends Fragment { ...@@ -65,7 +65,7 @@ public class PrivacyFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_privacy, container, false); return inflater.inflate(R.layout.fragment_record, container, false);
} }
// TODO: Rename method, update argument and hook method into UI event // TODO: Rename method, update argument and hook method into UI event
......
...@@ -7,7 +7,7 @@ import android.view.ViewGroup; ...@@ -7,7 +7,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.pojo.Setting; import com.example.zxa01.iotclient.common.pojo.Setting;
import java.util.LinkedList; import java.util.LinkedList;
......
...@@ -11,7 +11,7 @@ import android.view.View; ...@@ -11,7 +11,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.example.zxa01.iotclient.R; import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.pojo.Setting; import com.example.zxa01.iotclient.common.pojo.Setting;
import java.util.LinkedList; import java.util.LinkedList;
......
package com.example.zxa01.iotclient.login;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.home.HomeActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
public class LoginActivity extends AppCompatActivity {
@BindView(R.id.gateway)
EditText mGatewayView;
@BindView(R.id.account)
EditText mAccountView;
@BindView(R.id.password)
EditText mPasswordView;
@BindView(R.id.sign_in_button)
Button mSignInButton;
@BindView(R.id.linear_login_form)
LinearLayout mLayoutLoginForm;
private Activity activity = this;
private UserLoginTask mAuthTask = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
mSignInButton.setOnClickListener(view -> attemptLogin());
mLayoutLoginForm.setOnClickListener(view -> hideKeyboard(activity));
}
private void attemptLogin() {
if (mAuthTask != null) {
return;
}
mAccountView.setError(null);
mPasswordView.setError(null);
String gateway = mGatewayView.getText().toString();
String account = mAccountView.getText().toString();
String password = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// check
// if (!TextUtils.isEmpty(gateway) && !isLengthValid(gateway)) {
// mGatewayView.setError(getString(R.string.error_invalid_gateway));
// focusView = mGatewayView;
// cancel = true;
// }
// if (!TextUtils.isEmpty(password) && !isLengthValid(password)) {
// mPasswordView.setError(getString(R.string.error_invalid_password));
// focusView = mPasswordView;
// cancel = true;
// }
// if (TextUtils.isEmpty(account)) {
// mAccountView.setError(getString(R.string.error_field_required));
// focusView = mAccountView;
// cancel = true;
// } else if (!isLengthValid(account)) {
// mAccountView.setError(getString(R.string.error_invalid_account));
// focusView = mAccountView;
// cancel = true;
// }
if (cancel) {
focusView.requestFocus();
} else {
mAuthTask = new UserLoginTask(account, password);
mAuthTask.execute((Void) null);
}
}
private boolean isLengthValid(String text) {
return text.length() > 3;
}
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
private void startHomeActivity() {
Intent intent = new Intent(this, HomeActivity.class);
startActivity(intent);
}
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
private String mAccount;
private String mPassword;
UserLoginTask(String account, String password) {
mAccount = account;
mPassword = password;
}
@Override
protected Boolean doInBackground(Void... params) {
try {
// TODO: 帳號驗證
Thread.sleep(100);
} catch (InterruptedException e) {
return false;
}
return true;
}
@Override
protected void onPostExecute(final Boolean success) {
mAuthTask = null;
if (success) {
startHomeActivity();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
}
@Override
protected void onCancelled() {
mAuthTask = null;
}
}
}
package com.example.zxa01.iotclient.login.model;
import com.example.zxa01.iotclient.login.pojo.LoginMessage;
import android.arch.lifecycle.MutableLiveData;
import android.databinding.BaseObservable;
import android.support.annotation.NonNull;
public class LoginModel extends BaseObservable {
private MutableLiveData<Boolean> isAuthorized = new MutableLiveData<>();
public LoginModel() {
isAuthorized.setValue(false);
}
public MutableLiveData<Boolean> isAuthorized(){
return isAuthorized;
}
public void login(@NonNull LoginMessage message) {
isAuthorized.setValue(true);
// Callback<Object> callback = new Callback<Object>() {
// @Override
// public void onResponse(Call<Object> call, Response<Object> response) {
// // TODO login
// isAuthorized.setValue(true);
// }
//
// @Override
// public void onFailure(Call<Object> call, Throwable t) {
// Log.e("login - onFailure()", t.getMessage(), t);
// }
// };
//
// // TODO loginMessage to json
// Api.getApi().getDevices().enqueue(callback);
}
public void vaild() {
//TODO 驗證帳號格式
}
}
package com.example.zxa01.iotclient.login.pojo;
import android.support.annotation.NonNull;
public class LoginMessage {
private String gateway;
private String account;
private String password;
public LoginMessage() {
}
public LoginMessage(@NonNull String gateway, @NonNull String account, @NonNull String password) {
this.gateway = gateway;
this.account = account;
this.password = password;
}
public String getGateway() {
return gateway;
}
public void setGateway(String gateway) {
this.gateway = gateway;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.example.zxa01.iotclient.login.view;
import com.example.zxa01.iotclient.R;
import com.example.zxa01.iotclient.databinding.ActivityLoginBinding;
import com.example.zxa01.iotclient.login.viewModel.LoginViewModel;
import android.app.Activity;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public class LoginActivity extends AppCompatActivity {
private ActivityLoginBinding binding;
private LoginViewModel viewModel;
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
viewModel = new LoginViewModel(binding.getRoot().getContext());
binding.setViewModel(viewModel);
binding.linearLoginForm.setOnClickListener(view -> hideKeyboard(LoginActivity.this));
init();
}
private void init() {
viewModel.isAuthorized().observe(this,
isAuthorized -> viewModel.checkAuthorized(isAuthorized));
}
}
package com.example.zxa01.iotclient.login.viewModel;
import com.example.zxa01.iotclient.home.HomeActivity;
import com.example.zxa01.iotclient.login.model.LoginModel;
import com.example.zxa01.iotclient.login.pojo.LoginMessage;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Context;
import android.content.Intent;
import android.databinding.ObservableField;
public class LoginViewModel extends ViewModel {
public ObservableField<LoginMessage> loginMessage = new ObservableField<>();
private Context context;
private LoginModel loginModel = new LoginModel();
public LoginViewModel(Context context) {
this.loginMessage.set(new LoginMessage());
this.context = context;
}
public void login() {
loginModel.login(loginMessage.get());
}
public void checkAuthorized(Boolean isAuthorized) {
if (isAuthorized) {
context.startActivity(
new Intent(context, HomeActivity.class));
}
}
public MutableLiveData<Boolean> isAuthorized() {
return loginModel.isAuthorized();
}
}
package com.example.zxa01.iotclient.pojo;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
public class Device extends BaseObservable {
private int id;
private String name;
private String subTitle;
private String type;
private boolean status;
public Device(int id, String name, String subTitle, String type, boolean status) {
this.id = id;
this.name = name;
this.subTitle = subTitle;
this.type = type;
this.status = status;
}
public Device() {
}
@Bindable
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Bindable
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Bindable
public String getSubTitle() {
return subTitle;
}
public void setSubTitle(String subTitle) {
this.subTitle = subTitle;
}
@Bindable
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Bindable
public boolean isStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
}
package com.example.zxa01.iotclient.privacy;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class PrivacyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_privacy);
}
}
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
<item> <item>
<shape android:shape="rectangle"> <shape android:shape="rectangle">
<stroke <stroke
android:width="2dp" android:width="1dp"
android:color="@color/colorLighter" /> android:color="@color/colorLighter" />
<solid android:color="@color/colorWhite" /> <solid android:color="@color/colorWhite" />
</shape> </shape>
</item> </item>
<item <item
android:bottom="2dp"> android:bottom="1dp">
<shape android:shape="rectangle"> <shape android:shape="rectangle">
<stroke <stroke
android:width="2dp" android:width="1dp"
android:color="@color/colorWhite" /> android:color="@color/colorWhite" />
</shape> </shape>
</item> </item>
......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="3dp"
android:color="@color/colorLighter" />
<solid android:color="@color/colorWhite" />
</shape>
</item>
<item
android:bottom="3dp">
<shape android:shape="rectangle">
<stroke
android:width="3dp"
android:color="@color/colorWhite" />
</shape>
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:scrollbarAlwaysDrawHorizontalTrack="true"
tools:context=".detail.view.DetailActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_sm"
android:layout_marginTop="@dimen/margin"
android:layout_marginEnd="@dimen/margin_sm"
android:layout_marginBottom="@dimen/margin"
android:padding="@dimen/padding_sm"
android:background="@drawable/border_bottom_xl"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/tableLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textViewPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold"
android:text="隱私政策" />
<Button
android:id="@+id/buttonPrivacySetting"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="隱私偏好設定" />
<Button
android:id="@+id/buttonPrivacyReport"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="檢測報告" />
</LinearLayout>
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin"
android:padding="@dimen/padding_sm"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
tools:layout_editor_absoluteX="20dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewUDNKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="UDN"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewUDNValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewNameKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="裝置名稱"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewNameValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewTypeKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="裝置種類"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewTypeValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewManufacturerNameKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="製造商名稱"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewManufacturerNameValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewManufacturerUrlKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="製造商網址"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewManufacturerUrlValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewManufacturerSerialNumberKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="製造商序號"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewManufacturerSerialNumberValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewUDNKey6"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="製造商序號"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewUDNValue6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewModelNameKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="型號名稱"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewModelNameValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewModelUrlKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="型號網址"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewModelUrlValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewModelDescriptionKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="型號描述"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewModelDescriptionValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewLocationKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="位置"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewLocationValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewUPCKey"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_sm"
android:text="UPC"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewUPCValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="@dimen/margin_lg"
android:padding="@dimen/padding_sm"
android:text="TextView"
android:textSize="@dimen/font" />
</LinearLayout>
</TableRow>
</TableLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</layout>
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" app:menu="@menu/navigation" />
/>
<FrameLayout <FrameLayout
android:id="@+id/home_fragment_layout" android:id="@+id/home_fragment_layout"
...@@ -29,10 +28,8 @@ ...@@ -29,10 +28,8 @@
app:layout_constraintBottom_toTopOf="@+id/navigation" app:layout_constraintBottom_toTopOf="@+id/navigation"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent" />
</FrameLayout> </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</layout> </layout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.example.zxa01.iotclient.login.viewModel.LoginViewModel" />
</data>
<LinearLayout
android:id="@+id/linear_login_form" android:id="@+id/linear_login_form"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -10,7 +20,7 @@ ...@@ -10,7 +20,7 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".login.LoginActivity"> tools:context=".login.view.LoginActivity">
<ScrollView <ScrollView
android:layout_width="282dp" android:layout_width="282dp"
...@@ -40,7 +50,8 @@ ...@@ -40,7 +50,8 @@
android:hint="@string/prompt_gateway" android:hint="@string/prompt_gateway"
android:inputType="text" android:inputType="text"
android:maxLines="1" android:maxLines="1"
android:singleLine="true" /> android:singleLine="true"
android:text="@={viewModel.loginMessage.gateway}" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
...@@ -55,7 +66,8 @@ ...@@ -55,7 +66,8 @@
android:hint="@string/prompt_account" android:hint="@string/prompt_account"
android:inputType="text" android:inputType="text"
android:maxLines="1" android:maxLines="1"
android:singleLine="true" /> android:singleLine="true"
android:text="@={viewModel.loginMessage.account}" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
...@@ -72,7 +84,8 @@ ...@@ -72,7 +84,8 @@
android:imeOptions="actionUnspecified" android:imeOptions="actionUnspecified"
android:inputType="textPassword" android:inputType="textPassword"
android:maxLines="1" android:maxLines="1"
android:singleLine="true" /> android:singleLine="true"
android:text="@={viewModel.loginMessage.password}" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
...@@ -82,8 +95,11 @@ ...@@ -82,8 +95,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:onClick="@{()->viewModel.login()}"
android:text="@string/action_sign_in" android:text="@string/action_sign_in"
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>
</layout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".privacy.PrivacyActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Privacy"
tools:layout_editor_absoluteX="193dp"
tools:layout_editor_absoluteY="197dp" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
<data> <data>
<import type="android.view.View" />
<variable <variable
name="viewModel" name="viewModel"
type="com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel" /> type="com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel" />
</data> </data>
<FrameLayout <FrameLayout
...@@ -16,6 +17,7 @@ ...@@ -16,6 +17,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".home.device.view.DeviceFragment"> tools:context=".home.device.view.DeviceFragment">
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/device_recycler_view" android:id="@+id/device_recycler_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -25,6 +27,16 @@ ...@@ -25,6 +27,16 @@
app:setAdapter="@{viewModel.getAdapter()}" app:setAdapter="@{viewModel.getAdapter()}"
tools:listitem="@layout/recycler_view_device" /> tools:listitem="@layout/recycler_view_device" />
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:secondaryProgress="40"
android:theme="@style/ProgressTheme"
android:visibility="@{viewModel.isLoading ? View.VISIBLE : View.GONE}" />
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -34,6 +46,7 @@ ...@@ -34,6 +46,7 @@
android:src="@drawable/ic_add_black_24dp" android:src="@drawable/ic_add_black_24dp"
app:backgroundTint="@color/colorPrimary" /> app:backgroundTint="@color/colorPrimary" />
</FrameLayout> </FrameLayout>
</layout> </layout>
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".home.privacy.PrivacyFragment"> tools:context=".home.record.RecordFragment">
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="privacy" /> android:text="records" />
</FrameLayout> </FrameLayout>
\ No newline at end of file
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable <variable
name="position" name="position"
type="java.lang.Integer" /> type="java.lang.Integer" />
<variable <variable
name="viewModel" name="viewModel"
type="com.example.zxa01.iotclient.home.device.viewModel.DevicesViewModel" /> type="com.example.zxa01.iotclient.home.device.viewModel.DeviceViewModel" />
</data> </data>
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
android:layout_margin="@dimen/margin_sm" android:layout_margin="@dimen/margin_sm"
android:background="@drawable/shadow" android:background="@drawable/shadow"
android:elevation="2dp" android:elevation="2dp"
android:onClick="@{()->viewModel.onDevicesClick(position)}"
android:padding="@dimen/margin"> android:padding="@dimen/margin">
<ImageView <ImageView
...@@ -38,12 +40,12 @@ ...@@ -38,12 +40,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="@{viewModel.getDeviceAt(position).name}"
android:textColor="@color/colorGray" android:textColor="@color/colorGray"
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/text_device_subtitle" app:layout_constraintBottom_toTopOf="@+id/text_device_subtitle"
app:layout_constraintStart_toEndOf="@+id/image_device" app:layout_constraintStart_toEndOf="@+id/image_device"
app:layout_constraintTop_toTopOf="@+id/image_device" app:layout_constraintTop_toTopOf="@+id/image_device"
android:text="@{viewModel.getDeviceAt(position).device.name}"
tools:text="device name" /> tools:text="device name" />
<TextView <TextView
...@@ -51,14 +53,10 @@ ...@@ -51,14 +53,10 @@
android:layout_width="285dp" android:layout_width="285dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="8dp" android:text="@{viewModel.getDeviceAt(position).UDN}"
app:layout_constraintBottom_toBottomOf="@+id/image_device" app:layout_constraintBottom_toBottomOf="@+id/image_device"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.050"
app:layout_constraintStart_toEndOf="@+id/image_device" app:layout_constraintStart_toEndOf="@+id/image_device"
android:text="@{viewModel.getDeviceAt(position).device.subTitle}" tools:text="subtitle" />
tools:text="subtitle"
/>
<TextView <TextView
android:id="@+id/text_device_status" android:id="@+id/text_device_status"
...@@ -69,6 +67,7 @@ ...@@ -69,6 +67,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/image_device" app:layout_constraintTop_toTopOf="@+id/image_device"
tools:text="connection" /> tools:text="connection" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
</layout> </layout>
\ No newline at end of file
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
<item <item
android:id="@+id/navigation_home" android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp" android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_device" /> android:title="@string/nav_device" />
<item <item
android:id="@+id/navigation_privacy" android:id="@+id/navigation_privacy"
android:icon="@drawable/ic_lock_outline_black_24dp" android:icon="@drawable/ic_lock_outline_black_24dp"
android:title="@string/title_privacy" /> android:title="@string/nav_privacy" />
<item <item
android:id="@+id/navigation_setting" android:id="@+id/navigation_setting"
android:icon="@drawable/ic_settings_black_24dp" android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/title_setting" /> android:title="@string/nav_setting" />
</menu> </menu>
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
<resources> <resources>
<color name="colorPrimary">#1da1f2</color> <color name="colorPrimary">#1da1f2</color>
<color name="colorPrimaryDark">#0D92E1</color> <color name="colorPrimaryDark">#0D92E1</color>
<color name="colorAccent">#7e7266</color> <color name="colorAccent">#2A4474</color>
<color name="colorGray">#2d2d2d</color> <color name="colorGray">#2d2d2d</color>
<color name="colorLight">#808080</color> <color name="colorLight">#808080</color>
<color name="colorLighter">#dadada</color> <color name="colorLighter">#dadada</color>
<color name="colorWhite">#FFFFFF</color> <color name="colorWhite">#FFFFFF</color>
<color name="colorTransparent">#00000000</color>
</resources> </resources>
<resources> <resources>
<!--Title-->
<string name="title_detail">裝置資訊</string>
<string name="title_privacy">隱私政策</string>
<string name="title_setting">設定</string>
<string name="title_device_create">新增裝置</string>
<!--Home--> <!--Home-->
<string name="app_name">IOTClient</string> <string name="app_name">IOTClient</string>
<string name="title_device">Device</string> <string name="nav_device">Device</string>
<string name="title_privacy">Privacy</string> <string name="nav_privacy">Privacy</string>
<string name="title_setting">Setting</string> <string name="nav_setting">Setting</string>
<!--Create--> <!--Create-->
<string name="title_device_create">Create New Device</string> <string name="input_placeholder">請輸入裝置的UDN</string>
<string name="input_placeholder">the address of device</string>
<string name="button_qrcode">QRcode</string> <string name="button_qrcode">QRcode</string>
<string name="button_correct">Correct</string> <string name="button_correct">新增</string>
<string name="button_cancel">Cancel</string> <string name="button_cancel">返回</string>
<string name="qrcode_error">格式錯誤</string>
<!--Login--> <!--Login-->
<string name="action_sign_in">Log in</string> <string name="action_sign_in">登入</string>
<string name="login_iot_gateway">Login to IOT gateway</string> <string name="login_iot_gateway">Login to IOT gateway</string>
<string name="prompt_gateway">Gateway address</string> <string name="prompt_gateway">Gateway address</string>
<string name="prompt_account">Account</string> <string name="prompt_account">Account</string>
......
...@@ -8,4 +8,9 @@ ...@@ -8,4 +8,9 @@
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<!-- ProgressTheme. -->
<style name="ProgressTheme" parent="Widget.AppCompat.ProgressBar">
<item name="colorAccent">@color/colorPrimary</item>
</style>
</resources> </resources>
...@@ -7,7 +7,7 @@ buildscript { ...@@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
} }
......
#Fri Apr 12 13:02:55 CST 2019 #Sat Apr 20 17:56:49 CST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment