Skip to content

Commit

Permalink
v0.3 commit.
Browse files Browse the repository at this point in the history
Signed-off-by: Nachiketa Vadera <[email protected]>
  • Loading branch information
Nachiketa Vadera committed Jul 10, 2018
1 parent 04385ea commit 52e9cad
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 58 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down

This file was deleted.

25 changes: 25 additions & 0 deletions app/src/main/java/android/nachiketa/ebookdownloader/Global.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package android.nachiketa.ebookdownloader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Random;

public class Global {

public String getRandomQuote() throws IOException {
Random random = new Random();
StringBuilder builder = new StringBuilder();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("res/raw/quotes.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
int randomNumber = random.nextInt(37);
String[] temp = builder.toString().split("~");
return temp[randomNumber];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

@Override
Expand All @@ -18,30 +22,45 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,}, 1);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}

@Override
protected void onStart() {
super.onStart();
TextView textView = findViewById(R.id.tvDisplay);
try {
textView.setText(new Global().getRandomQuote());
} catch (IOException e) {
e.printStackTrace();
}
}

public void execute(View view) {
EditText etBookName = (EditText) findViewById(R.id.etBookName);
EditText etAuthor = (EditText) findViewById(R.id.etAuthor);

if (!etBookName.getText().toString().equals("")) {
if (!etAuthor.getText().toString().equals("")) {
Intent intent = new Intent(this, DownloadActivity.class);
intent.putExtra("bookName", etBookName.getText().toString());
intent.putExtra("author", etAuthor.getText().toString());
startActivity(intent);
}
else {
Toast.makeText(this, "Please enter name of the author", Toast.LENGTH_LONG).show();
}
}
else {
Toast.makeText(this, "Please enter the book name", Toast.LENGTH_LONG).show();
EditText etQuery = findViewById(R.id.etQuery);
RadioButton radBook = findViewById(R.id.radBookName);
RadioButton radAuthor = findViewById(R.id.radAuthor);

if (!etQuery.getText().toString().equals("")) {
String choice;
if (radBook.isChecked())
choice = "book";
else
choice = "author";
Intent intent = new Intent(this, DownloadActivity.class);
intent.putExtra("searchQuery", etQuery.getText().toString());
intent.putExtra("searchBy", choice);
startActivity(intent);
} else {
Toast.makeText(this, "Woah! You gotta give me something to work with", Toast.LENGTH_LONG).show();
etQuery.setFocusable(true);
}


}
}
}

// TODO : Change UI
// TODO : Add menu
// TODO : Optimize Libgen Parsing
43 changes: 27 additions & 16 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,49 @@
android:weightSum="4">

<EditText
android:id="@+id/etBookName"
android:id="@+id/etQuery"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="textAutoComplete"
android:hint="@string/et_hint_book"
android:hint="@string/et_hint_query"
android:text=""
android:textAlignment="center"
android:background="#FDD9E5" />

<EditText
android:id="@+id/etAuthor"
<RadioGroup
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:inputType="textAutoComplete"
android:hint="@string/et_hint_author"
android:text=""
android:textAlignment="center"
android:background="#FBF7D2" />
android:background="#FBF7D2"
android:orientation="horizontal"
android:weightSum="2">

<RadioButton
android:id="@+id/radBookName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:checked="true"
android:text="@string/radio_text_bookName"
android:textSize="20sp" />

<RadioButton
android:id="@+id/radAuthor"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/radio_text_author"
android:textSize="20sp" />

</RadioGroup>

<Button
android:id="@+id/btnDownload"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/button_text_download"
android:text="@string/button_text_search"
android:onClick="execute"
android:background="#CAF2E9" />

Expand All @@ -43,15 +59,10 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/text_quote"
android:text=""
android:textColor="#FCFFF7"
android:textSize="20sp"
android:textAlignment="center"
android:background="#283032" />

<WebView
android:id="@+id/wvDownload"
android:layout_width="0dp"
android:layout_height="0dp" />

</LinearLayout>
73 changes: 73 additions & 0 deletions app/src/main/res/raw/quotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
“Why? It's an excellent question. But an even better one is... Why not?” - Lara Whatley
~
“Don't cry because it's over, smile because it happened.” - Dr. Seuss
~
“Be yourself; everyone else is already taken.” - Oscar Wilde
~
“Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.” - Albert Einstein
~
“So many books, so little time.” - Frank Zappa
~
“To live is the rarest thing in the world. Most people exist, that is all.” - Oscar Wilde
~
“Without music, life would be a mistake.” - Friedrich Nietzsche
~
“We accept the love we think we deserve.” - Stephen Chbosky
~
“Insanity is doing the same thing, over and over again, but expecting different results.” - Narcotics Anonymous
~
“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.” - Jane Austen
~
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.” - Groucho Marx
~
“I have always imagined that Paradise will be a kind of library.” - Jorge Luis Borges
~
“Never trust anyone who has not brought a book with them.” - Lemony Snicket
~
“A day without sunshine is like, you know, night.” - Steve Martin
~
“I love deadlines. I love the whooshing noise they make as they go by.” - Douglas Adams
~
“Women and cats will do as they please, and men and dogs should relax and get used to the idea.” - Robert A. Heinlein
~
“All you need is love. But a little chocolate now and then doesn't hurt.” - Charles M. Schulz
~
“I find television very educating. Every time somebody turns on the set, I go into the other room and read a book.” - Groucho Marx
~
“I solemnly swear that I am up to no good.” - J.K. Rowling
~
“Some infinities are bigger than other infinities.” - John Green
~
“Some people never go crazy. What truly horrible lives they must lead.” - Charles Bukowski
~
“Time you enjoy wasting is not wasted time.” - Marthe Troly-Curtin
~
“Reality continues to ruin my life.” - Bill Watterson
~
“The only way out of the labyrinth of suffering is to forgive.” - John Green
~
“Go to heaven for the climate and hell for the company.” - Benjamin Franklin Wade
~
“You don’t forget the face of the person who was your last hope.” - Suzanne Collins
~
“I am free of all prejudice. I hate everyone equally. ” - W.C. Fields
~
“′Classic′ - a book which people praise and don't read.” - Mark Twain
~
“What a slut time is. She screws everybody.” - John Green
~
“The marks humans leave are too often scars.” - John Green
~
“I have never let my schooling interfere with my education.” - Mark Twain
~
“And, when you want something, all the universe conspires in helping you to achieve it.” - Paulo Coelho
~
“We believe in ordinary acts of bravery, in the courage that drives one person to stand up for another.” - Veronica Roth
~
“A lady's imagination is very rapid; it jumps from admiration to love, from love to matrimony in a moment.” - Jane Austen
~
“Some day you will be old enough to start reading fairy tales again.” - C.S. Lewis
~
“Books are a uniquely portable magic.” - Stephen King
~
“Have you ever noticed how ‘What the hell’ is always the right decision to make?” - Terry Johnson
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<string name="et_hint_author">Enter name of the author</string>
<string name="button_text_download">Download</string>
<string name="text_quote">“Humans, if nothing else, have the good sense to die.” - Markus Zusak</string>
<string name="button_text_search">Search</string>
<string name="et_hint_query">Enter search query</string>
<string name="radio_text_bookName">Search by Book</string>
<string name="radio_text_author">Search by Author</string>
</resources>

0 comments on commit 52e9cad

Please sign in to comment.