diff --git a/client/app/src/main/AndroidManifest.xml b/client/app/src/main/AndroidManifest.xml index 95053e42c..a976e8d13 100644 --- a/client/app/src/main/AndroidManifest.xml +++ b/client/app/src/main/AndroidManifest.xml @@ -5,8 +5,10 @@ + + + + + @@ -51,6 +59,12 @@ android:exported="true"> + + + { + // update UI + ArrayAdapter adapter = new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, android.R.id.text2, list); + // Assign adapter to ListView + listView.setAdapter(new CustomListViewAdapter(this, R.layout.custom_list_view_job, list)); + progressBar.setVisibility(View.GONE); + }); + } + + private class CustomListViewAdapter extends ArrayAdapter { + + private List mObjects; + private int layout; + + public CustomListViewAdapter(@NonNull Context context, int resource, @NonNull List objects) { + super(context, resource, objects); + mObjects = objects; + layout = resource; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + + JobServiceModel jobServiceModel = this.mObjects.get(position); + ViewHolder mainViewHolder = null; + if (convertView == null) { + LayoutInflater layoutInflater = LayoutInflater.from(getContext()); + convertView = layoutInflater.inflate(layout, parent, false); + + ViewHolder viewHolder = new ViewHolder(); + viewHolder.jobName = convertView.findViewById(R.id.jobName); + viewHolder.triggerJobButton = convertView.findViewById(R.id.triggerJob); + viewHolder.toggleActiveButton = convertView.findViewById(R.id.toggleActive); + viewHolder.toggleActiveButton.setChecked(jobServiceModel.getEnabled()); + + if (jobServiceModel.getActive() && jobServiceModel.getImplemented()) + viewHolder.jobName.setText(jobServiceModel.getName()); + else { + String name = ""; + if (!jobServiceModel.getActive()) + name = jobServiceModel.getName() + " (Not Active)"; + else + name = jobServiceModel.getName() + " (Not implemented)"; + viewHolder.jobName.setText(name); + viewHolder.toggleActiveButton.setEnabled(false); + viewHolder.triggerJobButton.setEnabled(false); + } + + convertView.setTag(viewHolder); + } + + mainViewHolder = (ViewHolder) convertView.getTag(); + + mainViewHolder.triggerJobButton.setOnClickListener(v -> { + Toast.makeText(JobServiceActivity.this, "Starting Job " + jobServiceModel.getName(), Toast.LENGTH_SHORT).show(); + try { + boolean triggered = jobServiceHelper.triggerJobService(jobServiceModel.getId()); + if(!triggered) + Toast.makeText(JobServiceActivity.this, jobServiceModel.getName() + " job failed. Cannot trigger disabled job.", Toast.LENGTH_SHORT).show(); + + } catch (Exception e) { + Log.e(TAG, jobServiceModel.getApiName() + " job failed", e); + Toast.makeText(JobServiceActivity.this, jobServiceModel.getName() + " job failed", Toast.LENGTH_SHORT).show(); + } + }); + + mainViewHolder.toggleActiveButton.setOnCheckedChangeListener((compoundButton, isChecked) -> { + Toast.makeText(JobServiceActivity.this, "Setting up job", Toast.LENGTH_SHORT).show(); + if (isChecked) { + try { + int resultCode = jobServiceHelper.scheduleJob(jobServiceModel.getId(), jobServiceModel.getApiName()); + + if (resultCode == JobScheduler.RESULT_SUCCESS) { + Log.d(TAG, "Job scheduled"); + Toast.makeText(JobServiceActivity.this, "Job scheduled", Toast.LENGTH_SHORT).show(); + } else { + Log.d(TAG, "Job scheduling failed"); + Toast.makeText(JobServiceActivity.this, "Job scheduling failed", Toast.LENGTH_SHORT).show(); + } + } catch (ClassNotFoundException e) { + Log.e(TAG, "Job scheduling failed : service " + jobServiceModel.getApiName() + " not implemented", e); + Toast.makeText(JobServiceActivity.this, "Job scheduling failed : service " + jobServiceModel.getApiName() + " not implemented", Toast.LENGTH_SHORT).show(); + compoundButton.setChecked(false); + } catch (Exception e) { + Log.e(TAG, "Job scheduling failed", e); + Toast.makeText(JobServiceActivity.this, "Job scheduling failed : " + e.getMessage(), Toast.LENGTH_SHORT).show(); + compoundButton.setChecked(false); + } + } else { + Toast.makeText(JobServiceActivity.this, "Cancelling Job", Toast.LENGTH_SHORT).show(); + try { + jobServiceHelper.cancelJob(jobServiceModel.getId()); + Log.d(TAG, "Job cancelled"); + Toast.makeText(JobServiceActivity.this, "Job cancelled", Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + Log.e(TAG, "Cancelling Job failed", e); + Toast.makeText(JobServiceActivity.this, "Cancelling Job failed", Toast.LENGTH_SHORT).show(); + } + } + }); + + return convertView; + } + } + + public class ViewHolder { + TextView jobName; + Button triggerJobButton; + Switch toggleActiveButton; + } +} \ No newline at end of file diff --git a/client/app/src/main/java/io/mosip/registration/app/activites/ListingActivity.java b/client/app/src/main/java/io/mosip/registration/app/activites/ListingActivity.java index f078e4824..67f51ff32 100644 --- a/client/app/src/main/java/io/mosip/registration/app/activites/ListingActivity.java +++ b/client/app/src/main/java/io/mosip/registration/app/activites/ListingActivity.java @@ -12,7 +12,7 @@ import androidx.lifecycle.ViewModelProvider; import dagger.android.support.DaggerAppCompatActivity; import io.mosip.registration.app.R; -import io.mosip.registration.app.viewmodel.ListingViewModel; +import io.mosip.registration.app.viewmodel.RegistrationPacketViewModel; import io.mosip.registration.app.viewmodel.ViewModelFactory; import io.mosip.registration.clientmanager.entity.Registration; import io.mosip.registration.clientmanager.spi.PacketService; @@ -40,9 +40,9 @@ public void onCreate(Bundle savedInstanceState) { getSupportActionBar().setTitle("Registrations"); getSupportActionBar().setSubtitle("Note : Packets are auto approved"); - ViewModelFactory viewModelFactory = new ViewModelFactory(new ListingViewModel(packetService)); - ListingViewModel model = new ViewModelProvider(this, viewModelFactory).get(ListingViewModel.class); - model.getRegistrationList().observe(this, list -> { + ViewModelFactory viewModelFactory = new ViewModelFactory(new RegistrationPacketViewModel(packetService)); + RegistrationPacketViewModel model = new ViewModelProvider(this, viewModelFactory).get(RegistrationPacketViewModel.class); + model.getList().observe(this, list -> { // update UI ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text2, list); @@ -118,3 +118,4 @@ public class ViewHolder { Button uploadButton; } } + diff --git a/client/app/src/main/java/io/mosip/registration/app/activites/MainActivity.java b/client/app/src/main/java/io/mosip/registration/app/activites/MainActivity.java index 6e0a8f7ce..4d5cea6be 100644 --- a/client/app/src/main/java/io/mosip/registration/app/activites/MainActivity.java +++ b/client/app/src/main/java/io/mosip/registration/app/activites/MainActivity.java @@ -52,5 +52,8 @@ public void click_list_packets(View view) { startActivity(intent); } - + public void click_list_JobService(View view) { + Intent intent = new Intent(this, JobServiceActivity.class); + startActivity(intent); + } } \ No newline at end of file diff --git a/client/app/src/main/java/io/mosip/registration/app/activites/ScreenActivity.java b/client/app/src/main/java/io/mosip/registration/app/activites/ScreenActivity.java index 1e59b2313..5521ce798 100644 --- a/client/app/src/main/java/io/mosip/registration/app/activites/ScreenActivity.java +++ b/client/app/src/main/java/io/mosip/registration/app/activites/ScreenActivity.java @@ -9,12 +9,16 @@ import android.view.View; import android.view.ViewGroup; import android.widget.*; + import androidx.annotation.Nullable; +import androidx.annotation.OptIn; import androidx.core.app.ActivityCompat; + import com.google.android.material.badge.BadgeDrawable; import com.google.android.material.badge.BadgeUtils; import com.scanlibrary.ScanActivity; import com.scanlibrary.ScanConstants; + import dagger.android.support.DaggerAppCompatActivity; import io.mosip.registration.app.R; import io.mosip.registration.app.dynamicviews.DynamicComponentFactory; @@ -26,11 +30,13 @@ import io.mosip.registration.clientmanager.repository.IdentitySchemaRepository; import io.mosip.registration.clientmanager.spi.MasterDataService; import io.mosip.registration.clientmanager.spi.RegistrationService; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import javax.inject.Inject; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -74,7 +80,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { String[] screens = getIntent().getExtras().getStringArray("screens"); int currentScreenIndex = getIntent().getExtras().getInt("nextScreenIndex"); - if(currentScreenIndex < screens.length) { + if (currentScreenIndex < screens.length) { ProcessSpecDto processSpecDto = identitySchemaRepository.getNewProcessSpec(getApplicationContext(), registrationService.getRegistrationDto().getSchemaVersion()); Optional screen = processSpecDto.getScreens().stream() @@ -82,38 +88,36 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { .findFirst(); //this can't happen at this stage - if(!screen.isPresent()) + if (!screen.isPresent()) throw new Exception("Invalid screen name found"); getSupportActionBar().setTitle(screen.get().getLabel().get(languages.get(0))); getSupportActionBar().setSubtitle(processSpecDto.getFlow()); loadScreenFields(screen.get(), languages); - } - else { + } else { //No more screens start loading preview screen Intent intent = new Intent(this, PreviewActivity.class); startActivity(intent); } final Button nextButton = findViewById(R.id.next); - nextButton.setOnClickListener( v -> { + nextButton.setOnClickListener(v -> { Optional view = currentDynamicViews.values() .stream() - .filter( d -> (d.isRequired() && !d.isValidValue())) + .filter(d -> (d.isRequired() && !d.isValidValue())) .findFirst(); - if(view.isPresent()) { - ((View)view.get()).requestFocus(); + if (view.isPresent()) { + ((View) view.get()).requestFocus(); nextButton.setError("Invalid value found"); - } - else { + } else { nextButton.setError(null); //start activity to render next screen Intent intent = new Intent(this, ScreenActivity.class); intent.putExtra("screens", screens); - intent.putExtra("nextScreenIndex", currentScreenIndex+1); + intent.putExtra("nextScreenIndex", currentScreenIndex + 1); startActivity(intent); finish(); } @@ -129,8 +133,8 @@ private void loadScreenFields(ScreenSpecDto screenSpecDto, List language fieldPanel.removeAllViews(); DynamicComponentFactory factory = new DynamicComponentFactory(getApplicationContext(), masterDataService); - for(FieldSpecDto fieldSpecDto : screenSpecDto.getFields()) { - if(fieldSpecDto.getInputRequired()) { + for (FieldSpecDto fieldSpecDto : screenSpecDto.getFields()) { + if (fieldSpecDto.getInputRequired()) { DynamicView dynamicView = null; switch (fieldSpecDto.getControlType().toLowerCase()) { case "textbox": @@ -160,8 +164,8 @@ private void loadScreenFields(ScreenSpecDto screenSpecDto, List language break; } - if(dynamicView != null) { - fieldPanel.addView((View)dynamicView); + if (dynamicView != null) { + fieldPanel.addView((View) dynamicView); currentDynamicViews.put(fieldSpecDto.getId(), dynamicView); this.registrationService.getRegistrationDto().addObserver((Observer) dynamicView); } @@ -175,12 +179,13 @@ public void goToHome() { } @Override + @OptIn(markerClass = com.google.android.material.badge.ExperimentalBadgeUtils.class) protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); String fieldId = requestCodeMap.get(requestCode); - if(resultCode == Activity.RESULT_OK) { + if (resultCode == Activity.RESULT_OK) { switch (requestCode) { - case 1 : + case 1: parseDiscoverResponse(data.getStringExtra("Response")); break; case 2: @@ -192,20 +197,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { default: if (requestCodeMap.containsKey(requestCode)) { Uri uri = data.getExtras().getParcelable(ScanConstants.SCANNED_RESULT); - try(InputStream iStream = getContentResolver().openInputStream(uri)) { + try (InputStream iStream = getContentResolver().openInputStream(uri)) { Spinner sItems = ((Spinner) ((View) currentDynamicViews.get(fieldId)).findViewById(R.id.doctypes_dropdown)); this.registrationService.getRegistrationDto().addDocument(fieldId, sItems.getSelectedItem().toString(), getBytes(iStream)); View view = ((View) currentDynamicViews.get(fieldId)).findViewById(R.id.doc_saved); view.setVisibility(View.VISIBLE); - BadgeDrawable badgeDrawable = BadgeDrawable.create(this); + BadgeDrawable badgeDrawable = BadgeDrawable.create(this); badgeDrawable.setNumber(this.registrationService.getRegistrationDto().getScannedPages(fieldId).size()); badgeDrawable.setVisible(true); BadgeUtils.attachBadgeDrawable(badgeDrawable, view); } catch (Exception e) { Log.e(TAG, "Failed to set document to registration dto", e); } - } - else + } else Toast.makeText(this, "Scan failed", Toast.LENGTH_LONG).show(); break; } @@ -214,14 +218,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { private void setRCaptureButtonListener(View view) { Button faceButton = view.findViewById(R.id.rcapture_face); - faceButton.setOnClickListener( v -> { + faceButton.setOnClickListener(v -> { discoverSBI("face"); }); } private void setScanButtonListener(int requestCode, View view, FieldSpecDto fieldSpecDto) { Button button = view.findViewById(R.id.scan_doc); - button.setOnClickListener( v -> { + button.setOnClickListener(v -> { int preference = ScanConstants.OPEN_CAMERA; Intent intent = new Intent(this, ScanActivity.class); intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference); @@ -229,7 +233,7 @@ private void setScanButtonListener(int requestCode, View view, FieldSpecDto fiel }); ImageButton previewButton = view.findViewById(R.id.doc_saved); - previewButton.setOnClickListener( v -> { + previewButton.setOnClickListener(v -> { Intent intent = new Intent(this, PreviewDocumentActivity.class); intent.putExtra("fieldId", fieldSpecDto.getId()); //TODO get label based on logged in language @@ -239,7 +243,7 @@ private void setScanButtonListener(int requestCode, View view, FieldSpecDto fiel } private byte[] getBytes(InputStream inputStream) throws IOException { - try(ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream()) { + try (ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream()) { int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; @@ -257,7 +261,7 @@ private void discoverSBI(String currentModality) { intent.setAction("sbi.reg.device"); List activities = this.getPackageManager().queryIntentActivities(intent, MATCH_DEFAULT_ONLY); if (activities.size() > 0) { - intent.putExtra("input", "{\"type\":\""+currentModality+"\"}"); + intent.putExtra("input", "{\"type\":\"" + currentModality + "\"}"); this.startActivityForResult(intent, 1); } else { Toast.makeText(getApplicationContext(), "Supported apps not found!", Toast.LENGTH_LONG).show(); @@ -265,8 +269,7 @@ private void discoverSBI(String currentModality) { } private void info(String callbackId) { - if (callbackId == null) - { + if (callbackId == null) { Toast.makeText(this, "No SBI found!", Toast.LENGTH_LONG).show(); return; } @@ -282,8 +285,7 @@ private void info(String callbackId) { } private void rcapture(String callbackId, String deviceId) { - if (deviceId == null || callbackId == null) - { + if (deviceId == null || callbackId == null) { Toast.makeText(this, "No SBI found!", Toast.LENGTH_LONG).show(); return; } @@ -365,12 +367,11 @@ private void parseRCaptureResponse(String response) { JSONArray jsonObject = new JSONObject(response).getJSONArray("biometrics"); String specVersion = jsonObject.getJSONObject(0).getString("specVersion"); String data = jsonObject.getJSONObject(0).getString("data"); - if(data == null || data.isEmpty()) { + if (data == null || data.isEmpty()) { JSONObject error = jsonObject.getJSONObject(0).getJSONObject("error"); Toast.makeText(getApplicationContext(), "Biometric Capture failed : " + error.toString(2), Toast.LENGTH_LONG).show(); - } - else { + } else { String signature = this.getSignature(data); byte[] payloadBuffer = this.getPayloadBuffer(data); String decodedPayload = new String(payloadBuffer); @@ -381,7 +382,7 @@ private void parseRCaptureResponse(String response) { //TODO - better way to handle all modalities BiometricsDto biometricsDto = new BiometricsDto("face", "face", specVersion, false, decodedPayload, signature, bioValue, qualityScore); - ((TextView)((View) currentDynamicViews.get("individualBiometrics")).findViewById(R.id.sbi_result)) + ((TextView) ((View) currentDynamicViews.get("individualBiometrics")).findViewById(R.id.sbi_result)) .setText(String.format("\nSpecVersion : %s \nQualityScore : %s", specVersion, qualityScore)); this.registrationService.getRegistrationDto().addBiometric("individualBiometrics", "face", biometricsDto); diff --git a/client/app/src/main/java/io/mosip/registration/app/util/JobServiceHelper.java b/client/app/src/main/java/io/mosip/registration/app/util/JobServiceHelper.java new file mode 100644 index 000000000..47bfb1ea8 --- /dev/null +++ b/client/app/src/main/java/io/mosip/registration/app/util/JobServiceHelper.java @@ -0,0 +1,79 @@ +package io.mosip.registration.app.util; + +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.content.ComponentName; +import android.content.Context; + +import io.mosip.registration.clientmanager.jobservice.PacketStatusSyncJob; +import io.mosip.registration.clientmanager.spi.PacketService; +import kotlin.NotImplementedError; + +public class JobServiceHelper { + + private static final String TAG = JobServiceHelper.class.getSimpleName(); + Context context; + JobScheduler jobScheduler; + PacketService packetService; + + public JobServiceHelper(Context context, JobScheduler jobScheduler, PacketService packetService) { + this.context = context; + this.jobScheduler = jobScheduler; + this.packetService = packetService; + } + + public int scheduleJob(int jobId, String apiName) throws ClassNotFoundException { + Class clientJobService = getJobServiceImplClass(apiName); + + if (clientJobService == null) { + throw new NotImplementedError("Job service : " + apiName + " not implemented"); + } + + ComponentName componentName = new ComponentName(context, clientJobService); + JobInfo info = new JobInfo.Builder(jobId, componentName) + .setRequiresCharging(false) + //.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED) + .setPersisted(true) + .setPeriodic(15 * 60 * 1000) + .build(); + + return jobScheduler.schedule(info); + } + + public boolean triggerJobService(int jobId) { + JobInfo info = jobScheduler.getPendingJob(jobId); + if (info == null) { + return false; + } + jobScheduler.schedule(info); + return true; + } + + public void cancelJob(int jobId) { + jobScheduler.cancel(jobId); + } + + public boolean isJobEnabled(int jobId) { + JobInfo jobinfo = jobScheduler.getPendingJob(jobId); + if (jobinfo == null) { + return false; + } + return true; + } + + public boolean isJobImplemented(String jobAPIName) { + if (getJobServiceImplClass(jobAPIName) == null) { + return false; + } + return true; + } + + public Class getJobServiceImplClass(String jobAPIName) { + switch (jobAPIName) { + case "packetSyncStatusJob": + return PacketStatusSyncJob.class; + default: + return null; + } + } +} diff --git a/client/app/src/main/java/io/mosip/registration/app/viewmodel/IListingViewModel.java b/client/app/src/main/java/io/mosip/registration/app/viewmodel/IListingViewModel.java new file mode 100644 index 000000000..ef1a93108 --- /dev/null +++ b/client/app/src/main/java/io/mosip/registration/app/viewmodel/IListingViewModel.java @@ -0,0 +1,9 @@ +package io.mosip.registration.app.viewmodel; + +import androidx.lifecycle.LiveData; + +import java.util.List; + +public interface IListingViewModel { + LiveData> getList(); +} diff --git a/client/app/src/main/java/io/mosip/registration/app/viewmodel/JobServiceViewModel.java b/client/app/src/main/java/io/mosip/registration/app/viewmodel/JobServiceViewModel.java new file mode 100644 index 000000000..47ffc22b3 --- /dev/null +++ b/client/app/src/main/java/io/mosip/registration/app/viewmodel/JobServiceViewModel.java @@ -0,0 +1,77 @@ +package io.mosip.registration.app.viewmodel; + +import android.util.Log; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import java.util.ArrayList; +import java.util.List; + +import io.mosip.registration.app.util.JobServiceHelper; +import io.mosip.registration.app.viewmodel.model.JobServiceModel; +import io.mosip.registration.clientmanager.entity.SyncJobDef; +import io.mosip.registration.clientmanager.spi.PacketService; + +public class JobServiceViewModel extends ViewModel implements IListingViewModel { + + private static final String TAG = JobServiceViewModel.class.getSimpleName(); + private static final int numLengthLimit = 5; + + JobServiceHelper jobServiceHelper; + PacketService packetService; + + public JobServiceViewModel(JobServiceHelper jobServiceHelper, PacketService packetService) { + this.jobServiceHelper = jobServiceHelper; + this.packetService = packetService; + } + + private MutableLiveData> jobServiceList; + + @Override + public LiveData> getList() { + if (jobServiceList == null) { + jobServiceList = new MutableLiveData<>(); + loadServices(); + } + return jobServiceList; + } + + private void loadServices() { + List jobServices = new ArrayList<>(); + + List syncJobDefList = packetService.getAllSyncJobDefList(); + for (SyncJobDef jobDef : syncJobDefList) { + + boolean isImplemented = jobServiceHelper.isJobImplemented(jobDef.getApiName()); + boolean isEnabled = jobServiceHelper.isJobEnabled(getId(jobDef.getId())); + + jobServices.add(new JobServiceModel( + getId(jobDef.getId()), + jobDef.getName(), + jobDef.getApiName(), + jobDef.getParentSyncJobId(), + jobDef.getSyncFreq(), + jobDef.getLockDuration(), + jobDef.getLangCode(), + jobDef.getIsDeleted(), + jobDef.getIsActive(), + isImplemented, + isEnabled + )); + } + + jobServiceList.setValue(jobServices); + } + + private int getId(String jobId) { + try { + String lastCharsWithNumLengthLimit = jobId.substring(jobId.length() - numLengthLimit); + return Integer.parseInt(lastCharsWithNumLengthLimit); + } catch (Exception ex) { + Log.e(TAG, "Conversion of jobId : " + jobId + "to int failed for length " + numLengthLimit + ex.getMessage()); + throw ex; + } + } +} diff --git a/client/app/src/main/java/io/mosip/registration/app/viewmodel/ListingViewModel.java b/client/app/src/main/java/io/mosip/registration/app/viewmodel/RegistrationPacketViewModel.java similarity index 76% rename from client/app/src/main/java/io/mosip/registration/app/viewmodel/ListingViewModel.java rename to client/app/src/main/java/io/mosip/registration/app/viewmodel/RegistrationPacketViewModel.java index 6431bb275..0122aeed2 100644 --- a/client/app/src/main/java/io/mosip/registration/app/viewmodel/ListingViewModel.java +++ b/client/app/src/main/java/io/mosip/registration/app/viewmodel/RegistrationPacketViewModel.java @@ -1,6 +1,5 @@ package io.mosip.registration.app.viewmodel; -import android.os.Handler; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; @@ -9,19 +8,20 @@ import java.util.List; -public class ListingViewModel extends ViewModel { +public class RegistrationPacketViewModel extends ViewModel implements IListingViewModel { - private static final String TAG = ListingViewModel.class.getSimpleName(); + private static final String TAG = RegistrationPacketViewModel.class.getSimpleName(); private PacketService packetService; - public ListingViewModel(PacketService packetService) { + public RegistrationPacketViewModel(PacketService packetService) { this.packetService = packetService; } private MutableLiveData> registrationList; - public LiveData> getRegistrationList() { + @Override + public LiveData> getList() { if (registrationList == null) { registrationList = new MutableLiveData<>(); loadRegistrations(); diff --git a/client/app/src/main/java/io/mosip/registration/app/viewmodel/ViewModelFactory.java b/client/app/src/main/java/io/mosip/registration/app/viewmodel/ViewModelFactory.java index 19568b5e6..bb92294d3 100644 --- a/client/app/src/main/java/io/mosip/registration/app/viewmodel/ViewModelFactory.java +++ b/client/app/src/main/java/io/mosip/registration/app/viewmodel/ViewModelFactory.java @@ -4,19 +4,19 @@ import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; -public class ViewModelFactory implements ViewModelProvider.Factory { +public class ViewModelFactory implements ViewModelProvider.Factory { - private ListingViewModel listingViewModel; + private T viewModel; - public ViewModelFactory(ListingViewModel listingViewModel) { - this.listingViewModel = listingViewModel; + public ViewModelFactory(T viewModel) { + this.viewModel = viewModel; } @NonNull @Override public T create(@NonNull Class modelClass) { - if(modelClass == ListingViewModel.class){ - return (T) this.listingViewModel; + if(IListingViewModel.class.isAssignableFrom(modelClass)){ + return (T) this.viewModel; }else{ throw new IllegalStateException("Unknown entity"); } diff --git a/client/app/src/main/java/io/mosip/registration/app/viewmodel/model/JobServiceModel.java b/client/app/src/main/java/io/mosip/registration/app/viewmodel/model/JobServiceModel.java new file mode 100644 index 000000000..86b443e36 --- /dev/null +++ b/client/app/src/main/java/io/mosip/registration/app/viewmodel/model/JobServiceModel.java @@ -0,0 +1,119 @@ +package io.mosip.registration.app.viewmodel.model; + + +public class JobServiceModel { + + private int id; + private String name; + private String apiName; + private String parentSyncJobId; + private String syncFreq; + private String lockDuration; + private String langCode; + private Boolean isDeleted; + private Boolean isActive; + private Boolean isImplemented; + private Boolean isEnabled; + + public JobServiceModel(int id, String name, String apiName, String parentSyncJobId, String syncFreq, String lockDuration, String langCode, Boolean isDeleted, Boolean isActive, Boolean isImplemented, Boolean isEnabled) { + this.id = id; + this.name = name; + this.apiName = apiName; + this.parentSyncJobId = parentSyncJobId; + this.syncFreq = syncFreq; + this.lockDuration = lockDuration; + this.langCode = langCode; + this.isDeleted = isDeleted; + this.isActive = isActive; + this.isImplemented = isImplemented; + this.isEnabled = isEnabled; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getApiName() { + return apiName; + } + + public void setApiName(String apiName) { + this.apiName = apiName; + } + + public String getParentSyncJobId() { + return parentSyncJobId; + } + + public void setParentSyncJobId(String parentSyncJobId) { + this.parentSyncJobId = parentSyncJobId; + } + + public String getSyncFreq() { + return syncFreq; + } + + public void setSyncFreq(String syncFreq) { + this.syncFreq = syncFreq; + } + + public String getLockDuration() { + return lockDuration; + } + + public void setLockDuration(String lockDuration) { + this.lockDuration = lockDuration; + } + + public String getLangCode() { + return langCode; + } + + public void setLangCode(String langCode) { + this.langCode = langCode; + } + + public Boolean getDeleted() { + return isDeleted; + } + + public void setDeleted(Boolean deleted) { + isDeleted = deleted; + } + + public Boolean getActive() { + return isActive; + } + + public void setActive(Boolean active) { + isActive = active; + } + + public Boolean getImplemented() { + return isImplemented; + } + + public void setImplemented(Boolean implemented) { + isImplemented = implemented; + } + + public Boolean getEnabled() { + return isEnabled; + } + + public void setEnabled(Boolean enabled) { + isEnabled = enabled; + } +} diff --git a/client/app/src/main/res/layout/activity_job_service.xml b/client/app/src/main/res/layout/activity_job_service.xml new file mode 100644 index 000000000..e97b4c1aa --- /dev/null +++ b/client/app/src/main/res/layout/activity_job_service.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/client/app/src/main/res/layout/activity_main.xml b/client/app/src/main/res/layout/activity_main.xml index 6fcf2fccb..91385d2ad 100644 --- a/client/app/src/main/res/layout/activity_main.xml +++ b/client/app/src/main/res/layout/activity_main.xml @@ -30,6 +30,14 @@ android:layout_height="wrap_content" android:onClick="click_list_packets" android:id="@+id/button15" /> + +