Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.

Commit 58402ca

Browse files
LaQuayeliseo-juan
andauthored
Develop (#17)
* update build version * Fixes (#14) - Añadido cacheo de imágenes - Muchos cambios visuales en la lista - Cambiada la lista por RecyclerView, con sus correspondientes animaciones al buscar - Solucionado un fallo al filtrar - Refactor de código * update settings screen * update exoplayer and gson * revert settings xml * update app version * detect source of media and update 0.5.6 * fix bug or * fix videoplayer when cross redirects * first version with favorites in TV * improve management with sharedpreferences * aadd app version checks * fix app version checks * bump exoplayer and glide versions * release v0.6.0 Co-authored-by: Eliseo Juan Quintanilla <v035173@gmail.com>
1 parent 2a2932c commit 58402ca

20 files changed

Lines changed: 255 additions & 49 deletions

mobile/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "laquay.com.canalestdt"
77
minSdkVersion 19
88
targetSdkVersion 29
9-
versionCode 10
10-
versionName "0.5.6"
9+
versionCode 11
10+
versionName "v0.6.0"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {
@@ -33,10 +33,10 @@ dependencies {
3333
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3434

3535
implementation 'com.android.volley:volley:1.1.1'
36-
implementation 'com.google.android.exoplayer:exoplayer:2.11.0'
36+
implementation 'com.google.android.exoplayer:exoplayer:2.11.1'
3737
implementation 'com.google.code.gson:gson:2.8.6'
3838

39-
implementation 'com.github.bumptech.glide:glide:4.10.0'
40-
implementation 'com.github.bumptech.glide:volley-integration:4.9.0'
41-
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
39+
implementation 'com.github.bumptech.glide:glide:4.11.0'
40+
implementation 'com.github.bumptech.glide:volley-integration:4.11.0'
41+
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
4242
}

mobile/src/main/java/laquay/com/canalestdt/ChannelListAdapter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
5050
holder.titleView.setText(channel.getChannel().getName());
5151
holder.subtitleView.setText(String.format("%s - %s", channel.getCountryName(), channel.getCommunityName()));
5252

53-
// Temporary fix
54-
String imageUrl = channel.getChannel().getLogo().replace("http://graph.facebook.com", "https://graph.facebook.com");
53+
String imageUrl = channel.getChannel().getLogo();
5554
Glide.with(context).load(imageUrl).placeholder(R.mipmap.ic_launcher).fallback(R.mipmap.ic_launcher).into(holder.imageView);
5655

5756
holder.itemView.setOnClickListener(new View.OnClickListener() {

mobile/src/main/java/laquay/com/canalestdt/DetailChannelActivity.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import android.net.Uri;
66
import android.os.Build;
77
import android.os.Bundle;
8+
import android.view.Menu;
9+
import android.view.MenuInflater;
10+
import android.view.MenuItem;
811
import android.view.View;
912
import android.widget.AdapterView;
1013
import android.widget.ArrayAdapter;
@@ -13,6 +16,7 @@
1316
import android.widget.TextView;
1417
import android.widget.Toast;
1518

19+
import androidx.annotation.NonNull;
1620
import androidx.appcompat.app.AppCompatActivity;
1721
import androidx.appcompat.widget.Toolbar;
1822
import androidx.core.content.ContextCompat;
@@ -28,6 +32,7 @@
2832
import laquay.com.canalestdt.controller.VolleyController;
2933
import laquay.com.canalestdt.model.Channel;
3034
import laquay.com.canalestdt.model.ChannelOptions;
35+
import laquay.com.canalestdt.utils.SourcesManagement;
3136
import laquay.com.canalestdt.utils.VideoUtils;
3237

3338
public class DetailChannelActivity extends AppCompatActivity {
@@ -42,7 +47,6 @@ public class DetailChannelActivity extends AppCompatActivity {
4247
private ImageView channelImageIV;
4348
private TextView channelNameTV;
4449
private TextView channelURLTV;
45-
private TextView channelSourceTV;
4650
private ListView channelSourceLV;
4751
private MediaPlayer mediaPlayer; //TODO This should be moved to another Dialog/Fragment
4852

@@ -79,12 +83,10 @@ private void setUpElements() {
7983
channelImageIV = findViewById(R.id.channel_image_detail_tv);
8084
channelNameTV = findViewById(R.id.channel_name_detail_tv);
8185
channelURLTV = findViewById(R.id.channel_url_detail_tv);
82-
channelSourceTV = findViewById(R.id.channel_source_detail_tv);
8386
channelSourceLV = findViewById(R.id.channel_source_detail_lv);
8487
}
8588

8689
private void setUpListeners() {
87-
8890
}
8991

9092
private void loadChannel() {
@@ -125,11 +127,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
125127
});
126128
}
127129

128-
// Temporary fix
129-
String imageUrl = channel.getLogo();
130-
imageUrl = imageUrl.replace("http://graph.facebook.com", "https://graph.facebook.com");
131-
132-
ImageRequest request = new ImageRequest(imageUrl,
130+
ImageRequest request = new ImageRequest(channel.getLogo(),
133131
new Response.Listener<Bitmap>() {
134132
@Override
135133
public void onResponse(Bitmap bitmap) {
@@ -178,4 +176,31 @@ public boolean onSupportNavigateUp() {
178176
onBackPressed();
179177
return true;
180178
}
179+
180+
@Override
181+
public boolean onCreateOptionsMenu(Menu menu) {
182+
MenuInflater inflater = getMenuInflater();
183+
inflater.inflate(R.menu.activity_detail_channel, menu);
184+
185+
if (SourcesManagement.isChannelFavorite(channel.getName())) {
186+
menu.getItem(0).setIcon(R.drawable.heart);
187+
} else {
188+
menu.getItem(0).setIcon(R.drawable.heart_outline);
189+
}
190+
return true;
191+
}
192+
193+
@Override
194+
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
195+
if (item.getItemId() == R.id.action_favorites) {
196+
boolean isItemFavorite = SourcesManagement.isChannelFavorite(channel.getName());
197+
if (isItemFavorite) {
198+
item.setIcon(R.drawable.heart_outline);
199+
} else {
200+
item.setIcon(R.drawable.heart);
201+
}
202+
SourcesManagement.setChannelFavorite(channel.getName(), !isItemFavorite);
203+
}
204+
return super.onOptionsItemSelected(item);
205+
}
181206
}

mobile/src/main/java/laquay/com/canalestdt/MainActivity.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
package laquay.com.canalestdt;
22

3+
import android.content.Context;
4+
import android.content.DialogInterface;
5+
import android.net.Uri;
36
import android.os.Bundle;
7+
import android.util.Log;
48
import android.view.MenuItem;
59

610
import androidx.annotation.NonNull;
11+
import androidx.appcompat.app.AlertDialog;
712
import androidx.appcompat.app.AppCompatActivity;
813
import androidx.appcompat.widget.Toolbar;
914
import androidx.fragment.app.Fragment;
1015
import androidx.fragment.app.FragmentTransaction;
1116

17+
import com.android.volley.Request;
18+
import com.android.volley.Response;
19+
import com.android.volley.VolleyError;
20+
import com.android.volley.toolbox.JsonObjectRequest;
1221
import com.google.android.material.bottomnavigation.BottomNavigationView;
1322

23+
import org.json.JSONException;
24+
import org.json.JSONObject;
25+
1426
import laquay.com.canalestdt.controller.SharedPreferencesController;
27+
import laquay.com.canalestdt.controller.VolleyController;
28+
import laquay.com.canalestdt.utils.Utils;
1529

1630
public class MainActivity extends AppCompatActivity {
31+
public static final String TAG = MainActivity.class.getSimpleName();
32+
1733
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
1834
= new BottomNavigationView.OnNavigationItemSelectedListener() {
1935

@@ -59,5 +75,57 @@ protected void onCreate(Bundle savedInstanceState) {
5975

6076
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
6177
navView.setSelectedItemId(R.id.nav_tv_channels);
78+
79+
checkAppVersion();
80+
}
81+
82+
private void checkAppVersion() {
83+
final String URL = "https://api.github.com/repos/laquay/TDTChannels-APP/releases/latest";
84+
final String versionName = BuildConfig.VERSION_NAME;
85+
final Context context = this;
86+
87+
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
88+
Request.Method.GET,
89+
URL,
90+
null,
91+
new Response.Listener<JSONObject>() {
92+
@Override
93+
public void onResponse(JSONObject response) {
94+
Log.i(TAG, "Response OK - " + URL);
95+
96+
try {
97+
String latestVersionName = response.getString("tag_name");
98+
99+
if (!latestVersionName.equals(versionName)) {
100+
AlertDialog.Builder alert = new AlertDialog.Builder(context);
101+
alert.setTitle(getString(R.string.download_new_version_title));
102+
alert.setMessage(getString(R.string.download_your_version_message) + ": " + versionName + "\n"
103+
+ getString(R.string.download_latest_version_message) + ": " + latestVersionName);
104+
alert.setPositiveButton(getString(R.string.download_yes), new DialogInterface.OnClickListener() {
105+
public void onClick(DialogInterface dialog, int whichButton) {
106+
Utils.launchIntent(context, Uri.parse("https://github.com/LaQuay/TDTChannels-APP/releases"));
107+
}
108+
});
109+
alert.setNegativeButton(getString(R.string.download_no), new DialogInterface.OnClickListener() {
110+
public void onClick(DialogInterface dialog, int whichButton) {
111+
}
112+
});
113+
alert.show();
114+
}
115+
} catch (JSONException e) {
116+
e.printStackTrace();
117+
}
118+
}
119+
},
120+
new Response.ErrorListener() {
121+
@Override
122+
public void onErrorResponse(VolleyError error) {
123+
Log.e(TAG, "Error while accessing to URL " + URL);
124+
}
125+
}
126+
);
127+
128+
// Add JsonArrayRequest to the RequestQueue
129+
VolleyController.getInstance(this).addToQueue(jsonObjectRequest);
62130
}
63131
}

mobile/src/main/java/laquay/com/canalestdt/TVFragment.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import laquay.com.canalestdt.model.Channel;
3636
import laquay.com.canalestdt.model.Community;
3737
import laquay.com.canalestdt.model.Country;
38+
import laquay.com.canalestdt.utils.SourcesManagement;
3839

3940
import static laquay.com.canalestdt.DetailChannelActivity.EXTRA_MESSAGE;
4041
import static laquay.com.canalestdt.DetailChannelActivity.EXTRA_TYPE;
@@ -49,6 +50,7 @@ public class TVFragment extends Fragment implements APIController.ResponseServer
4950
private ArrayList<Community> communities;
5051
private ArrayList<ChannelList> channelLists;
5152
private ChannelItemFilter mFilter = new ChannelItemFilter();
53+
private boolean isShowingFavorites;
5254

5355
public static TVFragment newInstance() {
5456
return new TVFragment();
@@ -97,34 +99,47 @@ public void onChannelsLoadServer(ArrayList<Country> countries) {
9799
Log.i(TAG, "Redrawing channels - Start");
98100
this.countries = countries;
99101
createChannelList();
100-
channelAdapter.submitList(channelLists);
101102
Log.i(TAG, "Redrawing channels - End");
102103
}
103104

104105
private void createChannelList() {
105106
channelLists = new ArrayList<>();
107+
106108
for (int i = 0; i < countries.size(); ++i) {
107109
communities = countries.get(i).getCommunities();
108110

109111
for (int j = 0; j < communities.size(); ++j) {
110112
ArrayList<Channel> channels = communities.get(j).getChannels();
111113

112-
boolean isCommunityShown = SharedPreferencesController.getInstance().getValue("" + communities.get(j).getName(), Boolean.class, true);
113-
if (isCommunityShown) {
114+
if (isShowingFavorites) {
114115
for (int k = 0; k < channels.size(); ++k) {
115-
channelLists.add(new ChannelList(countries.get(i).getName(),
116-
communities.get(j).getName(), channels.get(k)));
116+
if (SourcesManagement.isChannelFavorite(channels.get(k).getName())) {
117+
channelLists.add(new ChannelList(countries.get(i).getName(),
118+
communities.get(j).getName(), channels.get(k)));
119+
}
120+
}
121+
} else {
122+
boolean isCommunityShown = SourcesManagement.isCommunitySelected("" + communities.get(j).getName());
123+
if (isCommunityShown) {
124+
for (int k = 0; k < channels.size(); ++k) {
125+
channelLists.add(new ChannelList(countries.get(i).getName(),
126+
communities.get(j).getName(), channels.get(k)));
127+
}
117128
}
118129
}
119130
}
120131
}
132+
133+
channelAdapter.submitList(channelLists);
121134
}
122135

123136
@Override
124137
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
125138
menuInflater.inflate(R.menu.fragment_tv, menu);
126139
MenuItem searchItem = menu.findItem(R.id.action_search);
127140

141+
isShowingFavorites = false;
142+
128143
// Change color of the search button
129144
if (getContext() != null) {
130145
Drawable drawable = DrawableCompat.wrap(searchItem.getIcon());
@@ -150,16 +165,18 @@ public boolean onQueryTextChange(String newText) {
150165
});
151166
}
152167

153-
public void showDetails(ChannelList channel) {
154-
Intent intent = new Intent(getActivity(), DetailChannelActivity.class);
155-
intent.putExtra(EXTRA_MESSAGE, channel);
156-
intent.putExtra(EXTRA_TYPE, TYPE_TV);
157-
startActivity(intent);
158-
}
159-
160168
@Override
161169
public boolean onOptionsItemSelected(MenuItem item) {
162170
switch (item.getItemId()) {
171+
case R.id.action_favorites:
172+
if (isShowingFavorites) {
173+
item.setIcon(R.drawable.heart_outline);
174+
} else {
175+
item.setIcon(R.drawable.heart);
176+
}
177+
isShowingFavorites = !isShowingFavorites;
178+
createChannelList();
179+
return true;
163180
case R.id.action_filter:
164181
if (getContext() != null) {
165182
AlertDialog.Builder builder;
@@ -239,11 +256,9 @@ public void onClick(DialogInterface dialog, int which) {
239256
for (int z = 0; z < columnLayout.getChildCount(); ++z) {
240257
if (columnLayout.getChildAt(z) instanceof CheckBox) {
241258
CheckBox checkBox = (CheckBox) columnLayout.getChildAt(z);
242-
// TODO This should be inside a "lib"/"controller"
243-
SharedPreferencesController.getInstance().putValue("" + checkBox.getText(), checkBox.isChecked());
259+
SourcesManagement.setCommunitySelected("" + checkBox.getText(), checkBox.isChecked());
244260

245261
createChannelList();
246-
channelAdapter.submitList(channelLists);
247262
}
248263
}
249264
}
@@ -265,6 +280,12 @@ public void onClick(DialogInterface dialog, int which) {
265280
}
266281
}
267282

283+
public void showDetails(ChannelList channel) {
284+
Intent intent = new Intent(getActivity(), DetailChannelActivity.class);
285+
intent.putExtra(EXTRA_MESSAGE, channel);
286+
intent.putExtra(EXTRA_TYPE, TYPE_TV);
287+
startActivity(intent);
288+
}
268289

269290
private class ChannelItemFilter extends Filter {
270291
@Override

mobile/src/main/java/laquay/com/canalestdt/VideoDialogFragment.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
2020
import com.google.android.exoplayer2.ui.PlayerView;
2121
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
22+
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
23+
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
2224
import com.google.android.exoplayer2.util.Util;
2325

2426
public class VideoDialogFragment extends DialogFragment implements Player.EventListener {
@@ -56,9 +58,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5658
if (getActivity() != null && getContext() != null && channelUrl != null) {
5759
player = new SimpleExoPlayer.Builder(getContext()).build();
5860

59-
// Produces DataSource instances through which media data is loaded.
60-
dataSourceFactory = new DefaultDataSourceFactory(getContext(),
61-
Util.getUserAgent(getContext(), "laquay.com.canalestdt"));
61+
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
62+
Util.getUserAgent(getContext(), "laquay.com.canalestdt"),
63+
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
64+
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
65+
true
66+
);
67+
68+
dataSourceFactory = new DefaultDataSourceFactory(getContext(), httpDataSourceFactory);
6269

6370
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
6471
loadVideo(channelUrl);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package laquay.com.canalestdt.utils;
22

33
public class APIUtils {
4-
private static final String BASE_URL = "http://91.121.64.179/tdt_project/output/";
4+
private static final String BASE_URL = "http://www.tdtchannels.com/lists/";
55
public static final String TV_URL = BASE_URL + "channels.json";
66
public static final String RADIO_URL = BASE_URL + "radio_channels.json";
77
}

0 commit comments

Comments
 (0)