Skip to content

Commit

Permalink
Release 1.0.2 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwaters-stripe authored Jan 21, 2020
1 parent 8a6f1a4 commit 683dc81
Show file tree
Hide file tree
Showing 95 changed files with 368 additions and 350 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# 1.0.1
# 1.0.2

If you're using Gradle, update your build file to:

```
implementation "com.stripe:stripeterminal:1.0.1"
implementation "com.stripe:stripeterminal:1.0.2"
```

## Other changes
- Update gradle dependencies to work on latest gradle plugin
- Example apps (databinding specifically) now compile on latest gradle plugin
- Minor polish for multi-activity apps' lifecycle automatic cleanup

# 1.0.1

## Other changes
- Fixed race condition in multi-activity apps that could lead to DB exception

Expand Down
12 changes: 6 additions & 6 deletions Example/javaapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
targetSdkVersion 29
}

dataBinding {
enabled true
buildFeatures {
dataBinding = true
}

compileOptions {
Expand All @@ -31,18 +31,18 @@ ext {
constraintVersion = '1.1.3'
constraintlayoutVersion = '1.1.3'
coreTestingVersion = '2.1.0'
coroutineVersion = '1.3.2'
coroutineVersion = '1.3.3'
databindingVersion = '3.1.4'
legacysupportVersion = '1.0.0'
materialVersion = '1.0.0'
okhttpVersion = '4.2.2'
retrofitVersion = '2.6.2'
retrofitVersion = '2.7.0'
stethoVersion = '1.5.1'
viewModelVersion = '2.1.0'

leakCanaryVersion = '2.0-beta-3'
leakCanaryVersion = '2.0'

stripeTerminalVersion = '1.0.1'
stripeTerminalVersion = '1.0.2'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Application;
import android.os.StrictMode;
import androidx.lifecycle.ProcessLifecycleOwner;

import com.facebook.stetho.Stetho;
import com.stripe.stripeterminal.TerminalLifecycleObserver;
Expand Down Expand Up @@ -33,6 +34,7 @@ public void onCreate() {
Stetho.initializeWithDefaults(this);

registerActivityLifecycleCallbacks(observer);
ProcessLifecycleOwner.get().getLifecycle().addObserver(observer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.stripe.example.javaapp.NavigationListener;
import com.stripe.example.javaapp.R;
import com.stripe.example.javaapp.databinding.FragmentTerminalBinding;
import com.stripe.example.javaapp.viewmodel.TerminalViewModel;

import org.jetbrains.annotations.NotNull;
Expand All @@ -29,7 +25,6 @@ public class TerminalFragment extends Fragment {
public static final String TAG = "com.stripe.example.fragment.TerminalFragment";
private static final String SIMULATED_SWITCH = "simulated_switch";

private FragmentTerminalBinding binding;
private TerminalViewModel viewModel;

@Override
Expand All @@ -54,31 +49,21 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}
}

@Nullable
@Override
public View onCreateView(
@NotNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState
) {
// Inflate the layout for this fragment
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_terminal, container, false);
binding.setLifecycleOwner(this);
binding.setViewModel(viewModel);
return binding.getRoot();
}

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

view.findViewById(R.id.discover_button).setOnClickListener(v -> {
final FragmentActivity activity = getActivity();
if (activity instanceof NavigationListener) {
((NavigationListener) activity).onRequestDiscovery(viewModel.getSimulated());
((NavigationListener) activity).onRequestDiscovery(viewModel.simulated.getValue());
}
});

view.findViewById(R.id.simulated_switch).setOnClickListener(v -> {
viewModel.simulated.setValue(!viewModel.simulated.getValue());
});

// TODO: Do this dynamically from the type selected
((TextView) view.findViewById(R.id.device_type_button)).setText(R.string.chipper_2x);
}
Expand All @@ -90,7 +75,7 @@ public void onPause() {
if (activity != null) {
final SharedPreferences prefs = activity.getSharedPreferences(TAG, Context.MODE_PRIVATE);
if (prefs != null) {
prefs.edit().putBoolean(SIMULATED_SWITCH, viewModel.getSimulated()).apply();
prefs.edit().putBoolean(SIMULATED_SWITCH, viewModel.simulated.getValue()).apply();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.stripe.example.javaapp.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.databinding.DataBindingUtil;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import com.google.android.material.button.MaterialButton;
import com.stripe.example.javaapp.MainActivity;
import com.stripe.example.javaapp.R;
import com.stripe.example.javaapp.databinding.FragmentUpdateReaderBinding;
import com.stripe.example.javaapp.viewmodel.UpdateReaderViewModel;
import com.stripe.stripeterminal.Terminal;
import com.stripe.stripeterminal.callable.Callback;
Expand All @@ -22,6 +23,7 @@
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.Objects;

/**
* The `UpdateReaderFragment` allows the user to check the current version of the [Reader] software,
Expand All @@ -31,34 +33,16 @@ public class UpdateReaderFragment extends Fragment implements ReaderSoftwareUpda

@NotNull public static final String TAG = "com.stripe.example.fragment.UpdateReaderFragment";

private FragmentUpdateReaderBinding binding;
private UpdateReaderViewModel viewModel;
private WeakReference<MainActivity> activityRef;

@Override
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
viewModel = ViewModelProviders.of(this).get(UpdateReaderViewModel.class);
}

@Nullable
@Override
public View onCreateView(
@NotNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState
) {
// Inflate the layout for this fragment
binding = DataBindingUtil.inflate(
inflater, R.layout.fragment_update_reader, container, false);
binding.setLifecycleOwner(this);
binding.setViewModel(viewModel);

if (viewModel.reader == null) {
viewModel.reader = Terminal.getInstance().getConnectedReader();
}

return binding.getRoot();
}

@Override
Expand Down Expand Up @@ -141,6 +125,45 @@ public void onFailure(@NotNull TerminalException e) {

// Done button onClick listeners
view.findViewById(R.id.done_button).setOnClickListener(v -> exitWorkflow(activityRef));

viewModel.doneButtonVisibility.observe(this, visibility -> {
final TextView textView = view.findViewById(R.id.cancel_button);
textView.setTextColor(ContextCompat.getColor(
Objects.requireNonNull(getContext()),
visibility ? R.color.colorPrimaryDark : R.color.colorAccent));
view.findViewById(R.id.done_button)
.setVisibility(visibility ? View.VISIBLE : View.GONE);
});

((TextView) view.findViewById(R.id.reader_description)).setText(
Objects.requireNonNull(getContext()).getString(
R.string.reader_description,
Objects.requireNonNull(viewModel.reader).getDeviceType().name(),
viewModel.reader.getSerialNumber()));

((MaterialButton) view.findViewById(R.id.current_version)).setText(
viewModel.reader.getSoftwareVersion());

viewModel.checkForUpdateButtonVisibility.observe(this, visibility ->
view.findViewById(R.id.check_for_update_description)
.setVisibility(visibility ? View.VISIBLE : View.GONE));

viewModel.checkForUpdateButtonText.observe(this, text ->
((MaterialButton) view.findViewById(R.id.check_for_update_button)).setText(text));

viewModel.checkForUpdateButtonColor.observe(this, color ->
((MaterialButton) view.findViewById(R.id.check_for_update_button)).setTextColor(color));

viewModel.checkForUpdateDescriptionText.observe(this, text ->
((TextView) view.findViewById(R.id.check_for_update_description)).setText(text));

viewModel.checkForUpdateDescriptionVisibility.observe(this, visibility ->
view.findViewById(R.id.check_for_update_description)
.setVisibility(visibility ? View.VISIBLE : View.GONE));

viewModel.installDisclaimerVisibility.observe(this, visibility ->
view.findViewById(R.id.install_disclaimer)
.setVisibility(visibility ? View.VISIBLE : View.GONE));
}

private void onCompleteUpdate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.stripe.example.javaapp.fragment.event;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.stripe.example.javaapp.R;
import com.stripe.example.javaapp.model.Event;
import com.stripe.example.javaapp.viewmodel.EventViewModel;

import org.jetbrains.annotations.NotNull;

Expand All @@ -16,19 +18,10 @@
* Our [RecyclerView.Adapter] implementation that allows us to update the list of events
*/
public class EventAdapter extends RecyclerView.Adapter<EventHolder> {
@NotNull private final EventViewModel viewModel;
@NotNull private List<Event> events;

@BindingAdapter("events")
public static void bindEvents(@NotNull RecyclerView recyclerView, @NotNull List<Event> events) {
if (recyclerView.getAdapter() instanceof EventAdapter) {
((EventAdapter) recyclerView.getAdapter()).updateEvents(events);
}
}

public EventAdapter(@NotNull EventViewModel viewModel) {
public EventAdapter() {
super();
this.viewModel = viewModel;
events = new ArrayList<>();
}

Expand All @@ -50,6 +43,7 @@ public void onBindViewHolder(@NotNull EventHolder holder, int position) {
@NotNull
@Override
public EventHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
return new EventHolder(parent);
return new EventHolder(
LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_event, parent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.databinding.DataBindingUtil;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProviders;
Expand Down Expand Up @@ -160,7 +160,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityRef = new WeakReference<>(getActivity());
viewModel = ViewModelProviders.of(this).get(EventViewModel.class);
adapter = new EventAdapter(viewModel);

if (savedInstanceState == null) {
final Bundle arguments = getArguments();
Expand All @@ -184,27 +183,13 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}
}

@Nullable
@Override
public View onCreateView(
@NotNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState
) {
// Inflate the layout for this fragment
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_event, container, false);
binding.setLifecycleOwner(this);
binding.setViewModel(viewModel);

eventRecyclerView = binding.getRoot().findViewById(R.id.event_recycler_view);
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
eventRecyclerView = view.findViewById(R.id.event_recycler_view);
eventRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter = new EventAdapter();
eventRecyclerView.setAdapter(adapter);

return binding.getRoot();
}

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
view.findViewById(R.id.cancel_button).setOnClickListener(v -> {
if (viewModel.collectTask != null) {
viewModel.collectTask.cancel(new Callback() {
Expand All @@ -231,6 +216,16 @@ public void onFailure(@NotNull TerminalException e) {
activity.runOnUiThread(((NavigationListener) activity)::onRequestExitWorkflow);
}
});

viewModel.isComplete.observe(this, isComplete -> {
((TextView) view.findViewById(R.id.cancel_button))
.setTextColor(ContextCompat.getColor(getContext(),
isComplete ? R.color.colorPrimaryDark : R.color.colorAccent));

view.findViewById(R.id.done_button).setVisibility(isComplete ? View.VISIBLE : View.GONE);
});

viewModel.events.observe(this, events -> adapter.updateEvents(events));
}

@Override
Expand Down
Loading

0 comments on commit 683dc81

Please sign in to comment.